//
if(Greenfoot.getRandomNumber(50) < 1) addObject(new Zombie(), x, y)
if(Greenfoot.getRandomNumber(50) < 1) addObject(new Zombie(), Greenfoot.getRandomNumber(getWorld.getWidth()), Greenfoot.getRandomNumber(getWorld.getHeight()))
if(Greenfoot.getRandomNumber(50) < 1)
private int rate = 50, timer = 0;
if(Greenfoot.getRandomNumber(rate) < 1) addObject(new Zombie(), x, y)
public void act() { //Whatever else is in your act method if(Greenfoot.getRandomNumber(rate) < 1) addObject(new Zombie(), x, y) //1 in (rate) chance of spawning a zombie timer++; //increase the timer by 1 if(timer%100 == 0 && rate > 2) //when timer is 100, 200, 300, 400 etc, and the rate is more than 10 rate--; //decrease the rate variable by 1 }
if(Greenfoot.getRandomNumber(rate) < 1) ((ZombieWorld) getWorld()).addObject(new Zombie(), (int) Math.round(x), (int) Math.round(y));
if(Greenfoot.getRandomNumber(rate) < 1) getWorld().addObject(new Zombie(), (int) Math.round(x), (int) Math.round(y));
int spawnX = 0; int spawnY = 0; if (Greenfoot.getRandomNumber(2) == 0) // determines which axis to use { // spawns along top or bottom border spawnY = Greenfoot.getRandomNumber(2) * (getWorld().getHeight() - 1); // determines which side (top or bottom) spawnX = Greenfoot.getRandomNumber(getWorld().getWidth()); // determines where on that side to spawn Zombie at } else { // spawns along left or right border spawnX = Greenfoot.getRandomNumber(2) * (getWorld().getWidth() - 1); spawnY = Greenfoot.getRandomNumber(getWorld().getHeight()); } getWorld().addObject(new Zombie(), spawnX, spawnY);
if ( /* rate control check */ ) { // add zombie here }