What I would like to do is basically to spawn 2 Actors of the Class Maulwurf on a specific color, which are getting removed after some time and after that I want 2 new Actors of the Maulwurf Class to spawn. When I start my program, 2 actors of Maulwurf are spawning in the right position, but after they are getting removed, there aren't spawning new ones. It would be really kind if someone could help me fixing my problem^^
public raceTrack()
{
super(1000, 750, 1);
while (getObjects(Maulwurf.class).size() < 2)
{
int xPos = Greenfoot.getRandomNumber(getWidth());
int yPos = Greenfoot.getRandomNumber(getHeight());
Color color = (this).getColorAt(xPos, yPos);
if (color.getRed() == 77 && color.getGreen() == 77 && color.getBlue() == 77){
Maulwurf maulwurf = new Maulwurf();
addObject(maulwurf,xPos,yPos);
}
}
public class Maulwurf extends Actor
{
//Verschiedene Verzögerungszeiten werden festgelegt
private int delay1 = 150;
private int delay2 = 130;
private int delay3 = 105;
private int delay4 = 95;
private int delay5 = 90;
private int delay6 = 250;
public void act()
{
if (delay1 != 0)
{
delay1--;
return;
}
setImage("maulwurf_2.png");
if (delay2 != 0)
{
delay2--;
return;
}
setImage("maulwurf_3.png");
if (delay3 != 0)
{
delay3--;
return;
}
setImage("maulwurf_4.png");
if (delay4 != 0)
{
delay4--;
return;
}
setImage("maulwurf_5.png");
if (delay5 != 0)
{
delay5--;
return;
}
setImage("maulwurf_6.png");
if (delay6 != 0)
{
delay6--;
return;
}
getWorld().removeObjects(getWorld().getObjects(Maulwurf.class));
}
}
