How can stop a character from moving when it hits a wall in flash 8?

  • Thread starter Thread starter arsenalrkl
  • Start date Start date
A

arsenalrkl

Guest
Hey everybody my first post!

Overview
The character is locked to the screen and when one of the movement keys is pressed instead of the char moving, the map moves. Now there are walls in the map and when i press ctrl enter the char crosses over the walls. Can some one help stop the char from going over the walls?

Here's how movement works..

The Char is in the center of the screen and instead of the char moving around the map moves. The game is actually a 2d top down view shooter game. Like 2d counterstrike.

Now I made squares on the map and they are supposed to be obstacles (walls). But the char walks over them so how can i stop him from walking over them. Its called Hit Test I think and I want it so that when the character touches a square on screen and the char can't walk over the building.

If this is possible (which I am sure it is) may someone be able to upload an example of what i am talking about.


Thanks in Advance!
 
It has been a while since I have done this but something like


onClipEvent (enterFrame) {


if (Key.isDown(Key.UP)) {

_rotation = 0;
_y-= walkSpeed;

}

if (Key.isDown(key.RIGHT)) {

_rotation = 90;
_x+= walkSpeed;

}
if (Key.isDown(key.LEFT)) {

_rotation = 270;
_x-= walkSpeed;

}
if (Key.isDown(key.DOWN)) {

_rotation = 180;
_y+= walkSpeed;

}



}

just make the WalkSpeed negitive ? like if you move 10 pixels right make it move 10 pixels left basically sorry I can't be more spacific with the code its been a while.
 
Back
Top