So I'm programming Snake rn and I have this method to change directions of the snake, the only problem is that this method is only checked once per action thus making it possible to click a button and the snake doesn't react.
So the question is: Is it possible instead of checking once per move if a key is clicked to trigger a method as soon as a key is clicked?
Btw that's my code:
if(getRotation()==0) {
if(Greenfoot.isKeyDown("s")) {
turn(90);
}if(Greenfoot.isKeyDown("w")) {
turn(270);
}
}
if(getRotation()==90) {
if(Greenfoot.isKeyDown("a")) {
turn(90);
}if(Greenfoot.isKeyDown("d")) {
turn(270);
}
}
if(getRotation()==180) {
if(Greenfoot.isKeyDown("w")) {
turn(90);
}if(Greenfoot.isKeyDown("s")) {
turn(270);
}
}
if(getRotation()==270) {
if(Greenfoot.isKeyDown("d")) {
turn(90);
}if(Greenfoot.isKeyDown("a")) {
turn(270);
}
}

