This site requires JavaScript, please enable it in your browser!
Greenfoot back
TobiMobi
TobiMobi wrote ...

2019/6/26

Pacman

TobiMobi TobiMobi

2019/6/26

#
Hello, I have a question about Pacman. And over the walls. I made a keycontrol for my Pacman and it works perfectly but now I have the problem with the walls because the Pacman can walk trough the walls and I don't know how to code this. My ghosts are working perfectly if the hit a wall they turn and walk. But i can't copy this method because I don't want the Pacman to turn automatic and walk. The only thing I need is a method that says ,, If the Pacman hits a wall he can't continue to walk. I have 4 different types of walls ( WALL, WALLSMALL, WALL1, WALL1SMALL). Would be nice if you have some ideas. Thank you
danpost danpost

2019/6/26

#
All you need is something to this effect:
move(speed);
if (touchingWall()) move(-speed);
TobiMobi TobiMobi

2019/6/27

#
Sorry, but I don't understand where I have to put this code.
danpost danpost

2019/6/27

#
TobiMobi wrote...
Sorry, but I don't understand where I have to put this code.
In the act (or movement) method. Note that you may not yet have or want a touchingWall method and the specifics of wall collision detection is required there which results in a boolean (true/false) value. This is why I said "to this effect" (about the code given). It was more the idea that was being presented. You move the actor and if found touching any wall, just move it back. This will keep it off any walls (which includes stopping at a wall).
TobiMobi TobiMobi

2019/6/28

#
Ok, now I understand it. Thank you
You need to login to post a reply.