Skip to main content
Participating Frequently
December 1, 2006
Question

PacMan

  • December 1, 2006
  • 2 replies
  • 515 views
For this PacMan game I am making, I do not know how to add the code for the boudries, with an instance name of "walls". My PacMan guy can move around and stuff fine, but he goes through the walls, and that's a problem. Also, I don't know if the code goes under PacMan himself, or the walls that were converted to a movie clip named "Boundries". The code I have so far (that dos not work) is under PacMan:

if (walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= 1;
}

... I got it from the example of "Maze" in the examples folder of Flash MX.

Thanks!
This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
December 1, 2006
how does your pacman currently move? you must have a loop of some kind that repeatedly checks if the user is doing something (like pressing the right arrow key) and if-yes you have the pacman guy do something in response (like increase his _x property and move right).
Participating Frequently
December 1, 2006
Oh, sorry. This is the code for my PacMan's movements (Its under himself, the movieclip):

onClipEvent (load) {
moveSpeed = 7;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
_rotation = 180
}
else if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
_rotation = 90
}
else if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
_rotation = 270
}
else if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
_rotation = 0
}
}

Thanks again!
kglad
Community Expert
Community Expert
December 2, 2006
your enterFrame() event is your loop. you can put your hitTest() there. for example:

kglad
Community Expert
Community Expert
December 1, 2006
you should be using a hitTest() between your pacman guy and walls. and that hitTest() needs to be in a continually executing loop.

you would usually put that in the same loop that causes your pacman guy to move.
Participating Frequently
December 1, 2006
Wow, I'm an idiot, and have no clue what that means, or what it does. How do I make a "loop"?.... and I hope the code relates to the PacMan and the walls... how do I make sure it does that? Thanks again