So I'm making a simple Tron game, but I can move diagonally, which is bad. Here's my code
private int R = 1; private int L = 0; private int U = 0; private int D = 0; public boolean inUse = false; /** * Act - do whatever the PlayerOne wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { determineIfInUse(); if(inUse = false) { moveRight(); moveLeft(); moveUp(); moveDown(); } placeBeam(); } private void placeBeam() { getWorld().addObject(new PropOne(), getX(), getY()); } private void moveRight() { if (R == 1) { setRotation(0); setLocation(getX() + 5, getY()); if (Greenfoot.isKeyDown("down")) { R = 0; D = 1; } if (Greenfoot.isKeyDown("up")) { R = 0; U = 1; } } } private void moveLeft() { if (L == 1) { setRotation(0); setLocation(getX() - 5, getY()); if (Greenfoot.isKeyDown("down")) { L = 0; D = 1; } if (Greenfoot.isKeyDown("up")) { L = 0; U = 1; } } } private void moveUp() { if (U == 1) { setRotation(90); setLocation(getX(),getY() - 5); if (Greenfoot.isKeyDown("left")) { U = 0; L = 1; } if (Greenfoot.isKeyDown("right")) { U = 0; R = 1; } } } private void moveDown() { if (D == 1) { setRotation(90); setLocation(getX(), getY() + 5); if (Greenfoot.isKeyDown("left")) { D = 0; L = 1; } if (Greenfoot.isKeyDown("right")) { D = 0; R = 1; } } } private void determineIfInUse() { if (Greenfoot.isKeyDown("up") || Greenfoot.isKeyDown("down") || Greenfoot.isKeyDown("left") || Greenfoot.isKeyDown("right")) { inUse = true; } else { inUse = false; } }