ok so im trying to cap the number of wombats spawning so they dont explode and lag the prgram to death, but now they dont spawn at all?
and in the wombat there is not much as i put the spawning stuff in the world file
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Road here. * * @author (your name) * @version (a version number or a date) */ public class Road extends World { int delay = 1; /** * Constructor for objects of class Road. * */ public Road() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(800, 800, 1); prepare(); spawn(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { BABY1 baby1 = new BABY1(); addObject(baby1, 49, 630); BABY1 baby12 = new BABY1(); addObject(baby12, 62, 361); BABY1 baby13 = new BABY1(); addObject(baby13, 80, 181); baby13.setLocation(60, 319); baby1.setLocation(61, 406); Wombat wombat = new Wombat(); addObject(wombat, 736, 329); } public void spawn() { if (Greenfoot.getRandomNumber(100) == 1) { if (getObjects(Wombat.class).size() < 300) { addObject( new Wombat(),500+Greenfoot.getRandomNumber(798),1+Greenfoot.getRandomNumber(798)); } } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Wombat here. * * @author (your name) * @version (a version number or a date) */ public class Wombat extends Actor { int delay = 1; /** * Act - do whatever the Wombat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(-4); int yCoord = getY(); int xCoord = getX(); // if (yCoord <= 0 || yCoord >= 799) //{ // turn (180); //} if (xCoord ==0) { World Road = getWorld(); Road.removeObject (this); } } }