Hello, I have only started using Greenfoot recently and was wondering if anyone would be able to help me out with some coding for object spawning. Currently in my game, I have a playable character (Spy) that can pick up a stationary 'egg'. When this happens, I want the game to add 5 enemies I have named 'Alien1's in random locations throughout the world. This is the code I have currently in the egg class, however once the playable character picks up the egg, the 'Alien1's just continuously begin spawning. How can I change this code to put a limit on the number of 'Alien1's that are added into the world?
Thank you in advance
/** * this is the method whch tells the world to spawn aliens */ public void act() { if(isTouching(Spy.class)) { Spy c = (Spy) getOneIntersectingObject(Spy.class); setLocation(c.getX(),c.getY()); createNewAlien1(); } } private void createNewAlien1() /** * once the egg has been located and picked up, 5 Alien1's will spawn as an added threat */ { Alien1 newAlien1; newAlien1 = new Alien1(); World world; world = getWorld(); int worldWidth = world.getWidth(); int worldHeight = world.getHeight(); int x = Greenfoot.getRandomNumber(worldWidth); int y = Greenfoot.getRandomNumber(worldHeight); world.addObject(newAlien1, x, y); } }