I would like to make an object move left to right using the arrow and mouse keys as controls how can I do this?
public void move() {
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(), getY()-1);
}
if (Greenfoot.isKeyDown("down")) {
setLocation(getX(), getY()+1);
}
if (Greenfoot.isKeyDown("left")) {
setLocation(getX()-1, getY());
}
if (Greenfoot.isKeyDown("right")) {
setLocation(getX()+1, getY());
}
}public boolean atWorldEdge() {
if (getX() < 20 || getX() > getWorld().getWidth() - 20) {
return true;
}
if (getY() < 20 || getY() > getWorld().getHeight() - 20) {
return true;
}
}
return false;
}