I got this game where my ship has to avoid barrels. But the barrels are comming with 4 at once.. is it possible to set an interval between the spawning barrels? My code looks like this at the moment.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class barrel here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class barrel extends Actor
{
/* Act - do whatever the barrel wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.*/
public void act()
{
if(isGeraakt())
{
removeHealth();
getWorld().removeObject(this);
return;
}
int x = Greenfoot.getRandomNumber(2);
move(-x);
if(atWorldEdge()) getWorld().removeObject(this);
}
public void removeHealth()
{
BotenUpgrade subWorld = (BotenUpgrade) getWorld();
heart heartObject = (heart) subWorld.getObjects(heart.class).get(0);
heartObject.adjustValue(-1);
if (heartObject.getValue() == 0) removeLive();
}
public boolean isGeraakt()
{
boolean raak = false;
Actor r = getOneObjectAtOffset(0,0,boot.class);
if ( r !=null)
{
raak = true;
}
return raak;
}
public boolean atWorldEdge()
{
return getX() == 0 ||
getX() == getWorld().getWidth() - 1 ||
getY() == 0 ||
getY() == getWorld().getHeight() - 1;
}
public void removeLive()
{
int lives = getWorld().getObjects(heart.class).size();
getWorld().removeObject((Actor)getWorld().getObjects(heart.class).get(lives-1));
if (lives != 1)
{
//
}
else
{
Greenfoot.setWorld(new GameOver());
}
}
}
