I am making a game with controls similar to Frogger. I have finally gotten the frog to face the four directions I want to but now cannot think of the right way to type out how it should move when it is facing that direction. Another way to say this would be by pressing left to face to the left, and then left again to move in that direction. I set up an if statement but don't know where it went wrong. Maybe I am just too tired to see something simple, but please help.
Below is my code for this. The angles may seem weird, but it's only because the picture I used faced up to begin with so it's actually alright.
public void checkKeys() { String key = Greenfoot.getKey(); rotation = getRotation(); if ("right".equals(key)) { if ("0".equals(rotation)) {setLocation(getX() + 20, getY());} else {setRotation(90);} } if ("left".equals(key)) { if ("270".equals(rotation)) {setLocation(getX() - 20, getY());} else {setRotation(270);} } if ("up".equals(key)) { if ("0".equals(rotation)) {setLocation(getX(), getY() + 20);} else {setRotation(0);} } if ("down".equals(key)) { if("180".equals(rotation)) {setLocation(getX(), getY() - 20);} } }