how do you move your object up and down and side to side but without letting it go diagonally
if (Greenfoot.isKeyDown("up"))
moveUp();
else if (Greenfoot.isKeyDown("down"))
moveDown();
else if (Greenfoot.isKeyDown("left"))
moveLeft();
else if (Greenfoot.isKeyDown("right"))
moveRight();int dx = 0; // local field to hold movement along the x-axis
int dy = 0; // local field to hold movement along the y-axis
if (Greenfoot.isKeyDown("up")) dy--; // adjust y-axis movement upward
if (Greenfoot.isKeyDown("down")) dy++; // adjust y-axis movement downward
if (Greenfoot.isKeyDown("left")) dx--; // adjust x-axis movement toward left
if (Greenfoot.isKeyDown("right")) dx++; // adjust x-axis movement toward right
if (dx * dy == 0) setLocation(geX()+dx, getY()+dy); // if not diagonal movement, move (or stay, if no movement at all)