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.
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); } }