public void shoot() { if ("space".equals(Greenfoot.getKey())) { ball shot=new ball(); getWorld().addObject(shot,getX(),getY()); shot.setRotation(getRotation()); } }
public void shoot() { if ("space".equals(Greenfoot.getKey())) { ball shot=new ball(); getWorld().addObject(shot,getX(),getY()); shot.setRotation(getRotation()); } }
private int shotTimer; private boolean spaceDown; public void shoot() { if (shotTimer > 0 && --shotTimer > 0) return; // if timer running and not yet zero, exit method if (spaceDown != Greenfoot.isKeyDown("space")) // if change in state of trigger { spaceDown = !spaceDown; // record new trigger state if (spaceDown) // if new trigger state is down { ball shot = new ball(); getWorld().addObject(shot, getX(), getY()); shot.setRotation(getRotation()); } } }