Hello guys,
Currently in my mainWorld I have a method call setNextLevel() which basically add enemies at different position to set up the level. My question is how can I make it that the enemies spawn 1 by 1 after a set time instead of them spawning all at once. I tried to use a counter to count the number of acts and spawn them every x number of acts but it does not seem to work. Here is a sample of my code in the setNextLevel method.
// Initialize a new Array of red circles with enough spots for 4 red circles per level redCircle = new RedCircle [levelCounter * 4]; for (int i = 0; i < redCircle.length; i++) { //generate a random number between 1-4 to determine which side the enemies will spawn sideCounter = Greenfoot.getRandomNumber(4) + 1; // Initialize a new red circle object for each spot in the array redCircle[i] = new RedCircle (); //if statement to spawn each enemy in their appropriate side //spawn at the top if (sideCounter == 1) { // Add each red circle near the top of the screen addObject (redCircle[i], Greenfoot.getRandomNumber(890)+ 40, Greenfoot.getRandomNumber(10)+ 35); } //spawn on the right side else if (sideCounter == 2) { //Add each red circle near the right side of the screen addObject (redCircle[i],Greenfoot.getRandomNumber(20) + 915, Greenfoot.getRandomNumber(600) + 40); } //spawn at the bottom else if (sideCounter == 3) { //add each red circle near the bottom of the screen addObject (redCircle[i],Greenfoot.getRandomNumber(900) + 40 , Greenfoot.getRandomNumber(10) + 620); } //spawn on the left side else if (sideCounter == 4) { //add each red circle near the left side of the screen addObject (redCircle[i],Greenfoot.getRandomNumber(10) + 35 , Greenfoot.getRandomNumber(600) + 40); }