Trying to add a delay between when they spawn so they all dont spawn on top of each other. Tried adding a delay but still doesnt work.
Spawner:
Green:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Spawner here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Spawner extends Actor
{
/**
* Act - do whatever the Spawner wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public int zombies2kill = 5;
public int zombieskilled= 0;
public int zombies2spawn = 0;
private int delay = 0;
public void act()
{
if(delay > 0){
delay--;
}
if(delay == 0) spawn();
}
private void spawn(){
while(zombies2spawn <= zombies2kill){
Green green = new Green();
int lr = Greenfoot.getRandomNumber(3);
if(lr==2){
getWorld().addObject(green,580,380);
zombies2spawn++;
delay = 80;
}
if(lr==1){
getWorld().addObject(green,0,380);
zombies2spawn++;
delay = 80;
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class green here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Green extends Actor
{
/**
* Act - do whatever the green wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move(1);
if(isTouching(projectile_1.class)){
getWorld().removeObject(this);
}
}
}
