Is there anyway in greenfoot that through code I can say that this key is now pressed?
i.e.
if (Greenfoot.isKeyDown("d")) {
}
if (Greenfoot.isKeyDown("d")) {
dPressed();
}
private void dPressed() {
// code that you want to do when 'D' is pressed
// now you can call this method whenever you want to run the code that's in it
// instead of 'pressing a button through code'
}int dx = 0, dy = 0;
if (isAI())
{
// determine direction to move by setting dx and dy values to one of { -1, 0, 1 }
// maybe keeping last values and adjusting them would help to prevent oscillating movement
// turning at edges would help to keep from sticking to them
}
else
{
if (Greenfoot.isKeyDown("right")) dx++;
if (Greenfoot.isKeyDown("left")) dx--;
if (Greenfoot.isKeyDown("down")) dy++;
if (Greenfoot.isKeyDown("up")) dy--;
]