im trying to move only in the y direction (up and down). This is my code 2 and 3 are for the y movement, 3 is up and 2 is down. 3 works, but its much slower than moving left or right. Also 2 moves in a diagonal.
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 | public void move( int direction) { if (direction == 0 ) { int x = ( int ) Math.round(getX() + Math.cos( 0 ) * WALKING_SPEED); int y = ( int ) Math.round(getY() + Math.sin( 0 ) * WALKING_SPEED); setLocation(x, y); } if (direction == 1 ) { int x = ( int ) Math.round(getX() - Math.cos( 0 ) * WALKING_SPEED); int y = ( int ) Math.round(getY() + Math.sin( 0 ) * WALKING_SPEED); setLocation(x, y); } if (direction == 2 ) { int x = ( int ) Math.round(getX() + Math.cos(. 5 ) * WALKING_SPEED); int y = ( int ) Math.round(getY() + Math.sin( 0 ) * WALKING_SPEED); setLocation(y, x); } if (direction == 3 ) { int x = ( int ) (Math.round(getX() + Math.cos( 0 ) * WALKING_SPEED)) + (( int ) (Math.round(getX() - Math.cos( 0 ) * WALKING_SPEED))); int y = ( int ) (Math.round(getY() - Math.sin( 1 ) * WALKING_SPEED)) + (( int ) Math.round(getY() + Math.sin( 0 ) * WALKING_SPEED)); x = (x/ 2 ); y = (y/ 2 ); setLocation(x, y); } } |