How can I GLIDE for instance 10 boxes to the right with only pressing a button once, and not holding it down. (Important: it has to glide, it musn't jump)


// public void act() glide(); checkKeyPressed(); // public void checkKeyPressed() String myKey = Greenfoot.getKey(); if (myKey != null) { if ("up".equals(myKey)) { isGliding = true; glideStep = 0; glideDirection = 3; setRotation(270); } if ("right".equals(myKey) { isGliding = true; glideStep = 0; glideDirection = 0; setRotation(0); } if ("down".equals(myKey)) { isGliding = true; glideStep = 0; glideDirection = 1; setRotation(90); } if ("left".equals(myKey)) { isGliding = true glideStep = 0; glideDirection = 2; setRotation(0); } } // public void glide() if (isGliding) { if (glideDirection == 0) { if (getX() + 1 < getWorld().getWidth()) { setLocation(getX() + 1, getY()); } else { isGliding = false; } } if (glideDirection == 1) { if (getY() + 1 < getWorld().getHeight()) { setLocation(getX(), getY() + 1); } else { isGliding = false; } } if (glideDirection == 2) { if (getX() > 0) { setLocation(getX() - 1, getY()); } else { isGliding = false; } } if (glideDirection == 3) { if (getY() > 0) { setLocation(getX(), getY() - 1); } else { isGliding = false; } } if (isGliding) { glideStep++; if (glideStep == 10) { isGliding = false; } } }
public class Wombat extends Actor { private boolean isGliding = false; ... (etc)