Collision, and Next Frame

8 posts

Flag Post

I have Flash CS5.5 and I am making a game on AS3. It is a stick person game. So the collision part of my question. How can I add it so when the character tries to go off the sidewalk how do I make it so collision is there. Could you give me a code snip where it allows for collision but is wrote for keyboard movement with the arrow keys.
My other question is how do i make it so when my guy walks off the stage it automatically goes to next frame.

 
Flag Post
Originally posted by Zach71:

I have Flash CS5.5 and I am making a game on AS3. It is a stick person game. So the collision part of my question. How can I add it so when the character tries to go off the sidewalk how do I make it so collision is there. Could you give me a code snip where it allows for collision but is wrote for keyboard movement with the arrow keys.
My other question is how do i make it so when my guy walks off the stage it automatically goes to next frame.

If you are making a game where a character can walk up and down and if you want to restrict walkable area to only a sidewalk you can do it without collision for example:

var upPressed:Boolean = false;
var downPressed:Boolean = false; // Change these with keyboardEvent


///Put this into a loop///
if(downPressed && character.y > 400)
{
character.y += 2;
}

if(upPressed && character.y < 200)
{
character.y -= 2;
}

And if player walks out of the stage (to the right side)

////Loop////

if(player.x > 600)
{
////here remove all eventListeners
gotoAndStop(2)
}
 
Flag Post

The stage thing didn’t work and I am trying the sidewalk thing right now

 
Flag Post

collision also didnt work

 
Flag Post

what code do you have so far so we have something to work with

 
Flag Post

ok i will post my movement code thats all i really have so far for this part of the game.

 
Flag Post
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;


Person_mc.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);

function fl_MoveInDirectionOfKey(event:Event)
{ 
	if (upPressed)
	{
		Person_mc.y -= 5;
	}
	if (downPressed)
	{
		Person_mc.y += 5;
	}
	if (leftPressed)
	{
		Person_mc.x -= 5;
	}
	if (rightPressed)
	{
		Person_mc.x += 5;
	}
}

function fl_SetKeyPressed(event:KeyboardEvent):void
{
	switch (event.keyCode)
	{
		case Keyboard.UP:
		{
			upPressed = true;
			break;
		}
		case Keyboard.DOWN:
		{
			downPressed = true;
			break;
		}
		case Keyboard.LEFT:
		{
			leftPressed = true;
			break;
		}
		case Keyboard.RIGHT:
		{
			rightPressed = true;
			break;
		}
	}
}

function fl_UnsetKeyPressed(event:KeyboardEvent):void
{
	switch (event.keyCode)
	{
		case Keyboard.UP:
		{
			upPressed = false;
			break;
		}
		case Keyboard.DOWN:
		{
			downPressed = false;
			break;
		}
		case Keyboard.LEFT:
		{
			leftPressed = false;
			break;
		}
		case Keyboard.RIGHT:
		{
			rightPressed = false;
			break;
		}
	}
}
 
Flag Post

i dont understand what you mean