I am making pac man ( i am quite new to greenfoot so i want to learn, so i decided to by making pacman) I want to add walls so that pacman cannot pass through them (stops at the walls) Here is my pacman code
I just want PacMan to not be able to pass through walls (that you add in, which i dont know how to do so if you could help me with that, that would be nice) Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import greenfoot.*; /** * Write a description of class PacMan here. * * @author (your name) * @version (a version number or a date) */ public class PacMan extends Actor { /** * Act - do whatever the PacMan wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (Greenfoot.isKeyDown( "up" )) { setRotation( 0 ); turn(- 90 ); move( 5 ); } if (Greenfoot.isKeyDown( "down" )) { setRotation( 0 ); turn( 90 ); move( 5 ); } if (Greenfoot.isKeyDown( "left" )) { setRotation( 0 ); turn( 0 ); move(- 5 ); } if (Greenfoot.isKeyDown( "right" )) { setRotation( 0 ); turn( 0 ); move( 5 ); } } } |