The problem is that when the score reaches 50, the enemy should not respawn but still respawning.
public class avoiderWorld extends World
{
// Game Music//
private GreenfootSound Megalovania;
// Gpame Counter//
private Counter scoreBoard;
private int score = 0;
//Enemies Spawn Rate//
private int enemySpawnRate = 7;
private int enemy2SpawnRate = 7;
private int bossSpawnRate = 0;
private int meteorSpawnRate = 0;
//Enemies Speed //
private int enemySpeed = 1;
private int enemy2Speed = 1;
private int bossSpeed = 1;
private int meteorSpeed = 2;
//Score for eliminating an enemy//
private int enemyEliminatedScore = 1;
private int enemy2EliminatedScore = 1;
private int meteorEliminatedScore = 1;
// Score neede for new level and num. of levels//
private int newlvl = 25;
private int levels = 1;
public avoiderWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1, false);
//Plays this sound when the game starts//
Megalovania = new GreenfootSound("sounds/megalovania.wav");
Megalovania.playLoop();
prepare();
}
private void prepare()
{
//Adds this classes to the screen before starting the game//
avatar avatar = new avatar();
addObject(avatar,304,359);
avatar.setLocation(306,353);
scoreBoard = new Counter("Score: ");
addObject(scoreBoard, 70, 20);
}
public void act()
{
//randomly add enemies to the world//
if(Greenfoot.getRandomNumber(1500) < enemySpawnRate)
{
//creates a new class called enemy//
enemy e = new enemy();
//sets the speed variable, you have to give it a value( it, double, float)
e.setSpeed(enemySpeed);
//Spawns the enemies between the screen ranges that you set//
addObject(e, Greenfoot.getRandomNumber(getWidth()-20)+10, -30);
//increase points for each enemy spawned
scoreBoard.setValue(scoreBoard.getValue() + enemyEliminatedScore);
score += enemyEliminatedScore;
}
if(Greenfoot.getRandomNumber(1500) < enemy2SpawnRate)
{
enemy2 e2 = new enemy2();
e2.setSpeed(enemy2Speed);
addObject(e2, Greenfoot.getRandomNumber(getWidth()-20)+10, -30);
//increase points for each enemy2 spawned
scoreBoard.setValue(scoreBoard.getValue() + enemy2EliminatedScore);
score += enemyEliminatedScore;
}
if(Greenfoot.getRandomNumber(1500) < bossSpawnRate)
{
boss bs = new boss();
bs.setSpeed(bossSpeed);
addObject(bs,307,62);
scoreBoard.setValue(scoreBoard.getValue()+1);
}
if(Greenfoot.getRandomNumber(1500) < meteorSpawnRate)
{
meteor mtr = new meteor();
mtr.setSpeed(meteorSpeed);
addObject(mtr, Greenfoot.getRandomNumber(getWidth()-20)+10, -30);
scoreBoard.setValue(scoreBoard.getValue() + meteorEliminatedScore);
score += meteorEliminatedScore;
}
/*each time score is == to a multiple of 25 and is less than 100
run if statement that increases speed of both enemies*/
if(score == newlvl)
{
IncreaseLevel();
}
}
public void endGame()
{
//Displays the game over screen//
gameOverScreen go = new gameOverScreen();
Greenfoot.setWorld(go);
Megalovania.stop();
}
public void IncreaseLevel()
{
if(score == 25)
{
levels = 8;
}
switch(score)
{
//If score equals to a case, the case will execute it, and once reached the next score it will stop the actual case and start with the new one
case 25:
enemySpeed = 2;
enemy2Speed = 2;
break;
case 50:
enemySpawnRate = 0;
break;
case 75:
enemySpawnRate = 8;
break;
case 100:
enemy2SpawnRate = 8;
break;
case 125:
enemySpawnRate = 0;
enemy2SpawnRate = 0;
meteorSpawnRate = 10;
break;
case 150:
enemySpawnRate = 9;
enemy2SpawnRate = 8;
break;
case 175:
enemySpawnRate = 9;
enemy2SpawnRate = 9;
break;
case 200:
enemySpawnRate = 0;
enemy2SpawnRate = 0;
bossSpawnRate = 1;
break;
}
}
}

