I'm trying to get my other enemies to stop spawning once the Boss is spawned. Not sure how, any help is appreciated!
public class MarioWorld extends World
{
private GreenfootSound Music = new GreenfootSound("bgmusic.mp3");
private GreenfootSound bossMusic = new GreenfootSound("bossfight.mp3");
private int spawnTimer_;
ScoreBoard board = new ScoreBoard();
Lives lives = new Lives();
HealthBar bar = new HealthBar();
/**
* Constructor for objects of class MarioWorld.
*
*/
public MarioWorld()
{
// Create a new world with 1000x680 cells with a cell size of 1x1 pixels.
super(1000, 680, 1);
Mario hero = new Mario();
addObject(hero, getWidth()/2, getHeight()/2);
Lakitu player = new Lakitu(0.005);
addObject(player, 26, 35);
addObject(board, 876, 36);
addObject(lives, 92, 647);
spawnTimer_ = 0;
}
/**
* @return ScoreBoard
*/
public ScoreBoard getBoard()
{
return board;
}
/**
* @return Lives
*/
public Lives getLives()
{
return lives;
}
/**
* @return HealthBar
*/
public HealthBar getBar()
{
return bar;
}
/**
* Plays the music when the game is running.
*/
public void started()
{
Music.playLoop();
}
/**
* Stops the music when the game is stopped.
*/
public void stopped()
{
Music.stop();
bossMusic.stop();
}
public void act()
{
if(spawnTimer_ == 0) // same concept as reloadTimer_
{
spawnCheepCheep();
spawnGreenCC();
}
else
{
spawnTimer_ --;
}
spawnBoss();
}
/**
* Spawns the boss when Mario has collected 20 coins.
* Adds in the health bar when Mario has collected 20 coins.
* Starts the new music, and ends the old one.
*/
public void spawnBoss()
{
if(Mario.coinsCollected_ >= 20)
{
addObject(bar, 552, 127);
addObject(new Boss(), 1000, 340);
bossMusic.playLoop(); //starts the new music
Music.stop(); //stops the original music to play bossfight music
}
}
/**
* Spawns the amount of CheepCheep depending on the amount of coins Mario has collected.
* Difficulty increases(more CheepCheep spawned) when Mario collectes 15 or more coins.
*/
public void spawnCheepCheep()
{
//if Mario collects less than 15 coins, spawn 2 CC each time
if(Mario.coinsCollected_ < 15)
{
CheepCheep enemy = new CheepCheep();
CheepCheep enemy2 = new CheepCheep();
addObject(enemy, 0, Greenfoot.getRandomNumber(496)+92);
addObject(enemy2, 0, Greenfoot.getRandomNumber(496)+92);
spawnTimer_ = 250;
}
//if Mario collects 15 or more coins, start spawning an extra CC
//difficulty increases!
else if(Mario.coinsCollected_ >= 15)
{
CheepCheep enemy = new CheepCheep();
CheepCheep enemy2 = new CheepCheep();
CheepCheep enemy3 = new CheepCheep();
addObject(enemy, 0, Greenfoot.getRandomNumber(496)+92);
addObject(enemy2, 0, Greenfoot.getRandomNumber(496)+92);
addObject(enemy3, 0, Greenfoot.getRandomNumber(496)+92);
spawnTimer_ = 300;
}
}
/**
* Spawns the amount of GreenCC depending on the amount of coins Mario has collected.
* Difficulty increases as Mario collected 15 or more coins.
*/
public void spawnGreenCC()
{
// if Mario has less than 15 coins collected spawnn 2 CC at once
if(Mario.coinsCollected_ < 15)
{
GreenCC enemy3 = new GreenCC();
GreenCC enemy4 = new GreenCC();
addObject(enemy3, 1000, Greenfoot.getRandomNumber(496)+92);
addObject(enemy4, 1000, Greenfoot.getRandomNumber(496)+92);
spawnTimer_ = 200;
}
//if Mario collects 15 or more coins, then the number of CC spawns increases by 1
else if(Mario.coinsCollected_ >= 15)
{
GreenCC enemy3 = new GreenCC();
GreenCC enemy4 = new GreenCC();
GreenCC enemy5 = new GreenCC();
addObject(enemy3, 1000, Greenfoot.getRandomNumber(496)+92);
addObject(enemy4, 1000, Greenfoot.getRandomNumber(496)+92);
addObject(enemy5, 1000, Greenfoot.getRandomNumber(496)+92);
spawnTimer_ = 300;
}
}
}
