I want to have a bullet delay for the Shooter but I'm not sure how to code it
Here is the code for Shooter:
public class Shooter extends Actor
{
/**
* Act - do whatever the Shooter wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveAndTurn();
if(Greenfoot.isKeyDown("P"))
{
shoot();
}
}
public void shoot()
{
getWorld().addObject(new Bullet(), getX(), getY());
}
public Shooter()
{
GreenfootImage image = getImage();
image.scale(60, 40);
setImage(image);
}
public void moveAndTurn()
{
int speed = 4;
if(Greenfoot.isKeyDown("A")){
setLocation(getX() - speed, getY());
}
if(Greenfoot.isKeyDown("D")){
setLocation(getX() + speed, getY());
}
}
}
Here is the code for my bullets
public class Bullet extends Actor
{
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX(), getY() - 1);
GreenfootImage image = getImage();
image.scale(50, 10);
setImage(image);
if(checkBoundaries())
EliminateThePolice();
}
public boolean checkBoundaries()
{
if(getY()>555||getX()>555 ||getY()<5||getX()<5 ) {
getWorld().removeObject(this);
return false;
}
return true;
}
public void EliminateThePolice()
{
Actor Police = getOneIntersectingObject(Police.class);
if(Police !=null)
{
getWorld().removeObject(Police);
getWorld().removeObject(this);
}
}
}