Jump to content
  • Advertisement
Sign in to follow this  
coolkehon

Help with controls

This topic is 3258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm trying to get the controls working and i can't figure it out so while i try to figure it out i would like the help from those here. My character moves in an isometric world that isn't really isometric. I draw the image to the screen then setup bounds based on points and if it is inside of those bounds then it can move. I'm having problems getting the isometric controls right here is what i have so far.
void OverWorldCharacter::controlCallback(PadControls controls)
{
	Location next = loc;
//	if(controls.right() && controls.up())
//	{
//		if(room->is_walkable(Location(next.x+speed.x,next.y-speed.y)))
//		{
//			next.x += speed.x;
//			next.y -= speed.y;
//		}
//	}
//	else if(controls.right() && controls.down())
//	{
//		if(room->is_walkable(Location(next.x+speed.x,next.y+speed.y)))
//		{
//			next.x += speed.x;
//			next.y += speed.y;
//		}
//	}
//	else if(controls.left() && controls.up())
//	{
//		if(room->is_walkable(Location(next.x-speed.x,next.y-speed.y)))
//		{
//			next.x -= speed.x;
//			next.y -= speed.y;
//		}
//	}
//	else if(controls.left() && controls.down())
//	{
//		if(room->is_walkable(Location(next.x-speed.x,next.y+speed.y)))
//		{
//			next.x -= speed.x;
//			next.y += speed.y;
//		}
//	}
	
	u8 pdirect = direction;
	if(controls.right())
	{
		if(room->is_walkable(Location(next.x+speed.x,next.y)))
			next.x += speed.x;
		else if(room->is_walkable(Location(next.x+speed.x,next.y-speed.y)))
			next = Location(next.x+speed.x,next.y-speed.y);
		else if(room->is_walkable(Location(next.x+speed.x,next.y+speed.y)))
			next = Location(next.x+speed.x,next.y+speed.y);
		direction |= EAST;
//		standing_direction  = standing_direction & ~EAST;
		standing_direction = 0;
	}
	if(controls.left())
	{
		if(room->is_walkable(Location(next.x-speed.x,next.y)))
			next.x -= speed.x;
		else if(room->is_walkable(Location(next.x-speed.x,next.y+speed.y)))
			next = Location(next.x-speed.x,next.y+speed.y);
		else if(room->is_walkable(Location(next.x-speed.x,next.y-speed.y)))
				next = Location(next.x-speed.x,next.y-speed.y);
		direction |= WEST;
//		standing_direction  = standing_direction & ~WEST;
		standing_direction = 0;
	}
	if(controls.down())
	{
		if(room->is_walkable(Location(next.x,next.y+speed.y)))
			next.y += speed.y;
		else if(room->is_walkable(Location(next.x+speed.x,next.y+speed.y)))
			next = Location(next.x+speed.x,next.y+speed.y);
		else if(room->is_walkable(Location(next.x-speed.x,next.y+speed.y)))
			next = Location(next.x-speed.x,next.y+speed.y);
		direction |= SOUTH;
//		standing_direction  = standing_direction & ~SOUTH;
		standing_direction = 0;
	}
	if(controls.up())
	{
		if(room->is_walkable(Location(next.x,next.y-speed.y)))
			next.y -=speed.y;
		else if(room->is_walkable(Location(next.x-speed.x,next.y-speed.y)))
			next = Location(next.x-speed.x,next.y-speed.y);
		else if(room->is_walkable(Location(next.x+speed.x,next.y-speed.y)))
			next = Location(next.x+speed.x,next.y-speed.y);
		direction |= NORTH;
//		standing_direction = standing_direction & ~NORTH;
		standing_direction = 0;
	}
	
	if(next.x != loc.x || next.y != loc.y)
	{
		loc = next;
//		room->moveTo((480.0f/2.0f)-lan_loc.x,(272.0f/2.0f)-lan_loc.y);
		room->moveTo(240.0f-loc.x,136-loc.y);
	}
	
//	if(controls.pressed() & PSP_CTRL_UP)
//		direction |= NORTH;
//	if(controls.pressed() & PSP_CTRL_DOWN)
//		direction |= SOUTH;
//	if(controls.pressed() & PSP_CTRL_RIGHT)
//		direction |= EAST;
//	if(controls.pressed() & PSP_CTRL_LEFT)
//		direction |= WEST;
	
	if(controls.released() & PSP_CTRL_UP)
	{
		direction = direction & ~NORTH;
		standing_direction |= NORTH;
	}
	if(controls.released() & PSP_CTRL_DOWN)
	{
		direction = direction & ~SOUTH;
		standing_direction |= SOUTH;
	}
	if(controls.released() & PSP_CTRL_RIGHT)
	{
		direction = direction & ~EAST;
		standing_direction |= EAST;
	}
	if(controls.released() & PSP_CTRL_LEFT)
	{
		direction = direction & ~WEST;
		standing_direction |= WEST;
	}
	
	if(sprite == NULL) return;
	if(pdirect != direction)
	{
		pdirect = direction;
		if(direction & NORTHEAST)
		{
			
		}
		else if(direction & NORTHWEST)
		{
			
		}
		else if(direction & SOUTHEAST)
		{
			
		}
		else if(direction & SOUTHWEST)
		{
			
		}
		else
		{
			sprite->stopAnim();
			if(standing_direction & EAST)
				sprite->setFrame(2,0);
			else if(standing_direction & NORTH)
				sprite->setFrame(0,0);
			else if(standing_direction & SOUTH)
				sprite->setFrame(4,0);
		}
	}
//Updates sprite
	sprite->update();
}

[Edited by - coolkehon on August 16, 2009 9:14:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
i figured it out. but what about when it goes on a wall. i want it to slide down the wall if it can't go any further but the insidepolygon function doesnt work with this to well

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!