So I wanted to my move object with arrow keys(UP,DOWN,LEFT,RIGHT). I've done that. But now I'm trying to move it also UP & RIGHT, UP & LEFT, DOWN & RIGHT and DOWN & Left. Of course by pressing the 2 corresponding arrows at the same time. However, my code so far will only rotate the object's image in two of those directions (DOWN RIGHT, DOWN LEFT).
I noticed that when I move around the if statement that controls the two arrow keys, the image will either rotate or won't rotate in that certain directions. My brain is just out of ideas how to fix this and I gave up, so I came here for help. The image which I rotate is the default Greenfoot rocket ship.
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 | public void playerMove() { int dx= 10 , dy= 10 ; if (Greenfoot.isKeyDown( "up" )) dy--; if (Greenfoot.isKeyDown( "down" )) dy++; if (Greenfoot.isKeyDown( "right" )) dx++; if (Greenfoot.isKeyDown( "left" )) dx--; if (dx< 10 && dy< 0 ) // left up { setRotation( 225 ); move(speed); } else if (dy< 10 ) //up { setRotation( 270 ); move(speed); } if (dx> 10 && dy< 10 ) // right up { setRotation( 315 ); move(speed); } else if (dy> 10 ) //down { setRotation( 90 ); move(speed); } if (dx> 10 && dy> 10 ) // right down { setRotation( 45 ); move(speed); } else if (dx> 10 ) //right { setRotation( 0 ); move(speed); } if (dx< 10 && dy> 10 ) //left down { setRotation( 135 ); move(speed); } else if (dx< 10 ) //left { setRotation( 180 ); move(speed); } |