I'm making a maze game, and I've been unsuccessfully trying to make the walls of the maze barriers that the player cannot pass. I've tried multiple ways, yet nothing seems to work. The player just passes through the walls like they're not even there. The class the "Player" class cant pass is the "MazeLines" class. I just need some guidance on where to start with this, as getOneIntersectingObject has failed every time I've tried it.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | public class Player extends Animal { private int coinsCollected = 0 ; private GreenfootImage image1; private GreenfootImage image2; private GreenfootImage image3; private int deltaX; private int deltaY; static final int CHANGE_RATE = 3 ; int changeImgNum = 1 ; int imageNum= 1 ; String[]images={ "Walking1.png" , "Walking2.png" }; /** * Act - do whatever the Player wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { image1= new GreenfootImage( "stickMan.png" ); image2= new GreenfootImage( "Walking1.png" ); image3= new GreenfootImage( "Walking2.png" ); setImage(image1); move(); checkWalls(); coinsCollected= 0 ; getCoin(); Finish(); } public void move() { //make WASD move the player. if (Greenfoot.isKeyDown( "w" )) { setImage(image2); animateWalk(); setRotation( 270 ); move( 2 ); } if (Greenfoot.isKeyDown( "a" )) { setImage(image2); animateWalk(); setRotation( 180 ); move( 2 ); } if (Greenfoot.isKeyDown( "s" )) { setImage(image2); animateWalk(); setRotation( 90 ); move( 2 ); } if (Greenfoot.isKeyDown( "d" )) { setImage(image2); animateWalk(); setRotation( 0 ); move( 2 ); } } public void animateWalk() //animation only shows walking2.png for a second, needs to be longer { changeImgNum--; if (changeImgNum== 0 ) { changeImgNum = CHANGE_RATE; imageNum=(imageNum+ 1 )% 2 ; setImage(images[imageNum]); } } public void getCoin() //Collect coins { if (canSee(Coin. class )) { eat(Coin. class ); Greenfoot.playSound( "Coin.wav" ); coinsCollected++; } } public void Finish() { if (canSee(Finish. class )) { eat(Finish. class ); Greenfoot.playSound( "Clear.wav" ); Greenfoot.stop(); } } public void checkWalls() { } } |