My character only turns when it hits one wall but doesn't turn when it hits the other. Help please!
Here's the code that i have:
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 | public void act() { moveAround(); } public boolean hitWall() { if (isTouching (wall. class )) { return true ; } else { return false ; } } public void moveAround() { move( 3 ); if (isTouching (wall. class )== true ) { move(- 3 ); int i = Greenfoot.getRandomNumber( 3 ); if (i== 1 ) { setRotation( 180 ); i= 0 ; } if (i== 2 ) { setRotation( 180 ); i= 0 ; } } } |