The game starts by killing the first type of enemy. I have a condition that when a number of enemies are dead it will switch to a different scenario(Shop) where they can purchase weapons, I have this "back button"(actor) that when it is clicked. It will switch back to the myWorld. but instead of killing the same type of enemies I want to spawn Golem(actor) instead.
This is the code I have in myWorld ,, This is like my main level.
##### This is the code I have in my Shop class
public void act()
{
count++;
swtichToShop();
if (currentLevel == 1)
{
spawnZombies();
}
else if ( currentLevel == 2)
{
spawnGolem();
}
} public void spawnZombies()
{
if( count % spawnSpeed == 0)
{
randomSpawn = Greenfoot.getRandomNumber(8);
switch(randomSpawn){
case 0 : addObject(new Ghost(hero, counter), 0, 0);break;
case 1 : addObject(new Ghost(hero, counter), getWidth()/2, 0);break;
case 2 : addObject(new Ghost(hero, counter), getWidth(), 0);break;
case 3 : addObject(new Ghost(hero, counter), 0, getHeight()/2);break;
case 4 : addObject(new Ghost(hero, counter), getWidth(), getHeight()/2);break;
case 5 : addObject(new Ghost(hero, counter), 0, getHeight()); break;
case 6 : addObject(new Ghost(hero, counter), getWidth()/2, getHeight());break;
case 7 : addObject(new Ghost(hero, counter), getWidth(), getHeight()); break;
}
}
}
public void spawnGolem()
{
if( count % spawnSpeed == 0)
{
randomSpawn = Greenfoot.getRandomNumber(5);
switch(randomSpawn){
case 0 : addObject(new Golem(hero, counter), 0, 0);break;// top left
case 1 : addObject(new Golem(hero, counter), getWidth(), 0);break;//top right
case 2 : addObject(new Golem(hero, counter), 0, getHeight()); break;//bottom left
case 3 : addObject(new Golem(hero, counter), getWidth(), getHeight()); break;//bottom right
}
}
}public class Shop extends World
{
Counter counter;
MyWorld myWorld = new MyWorld();
Back back = new Back();
/**
* Constructor for objects of class Shop.
*
*/
public Shop()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 600, 1);
addObject(back,130,550);
getBackground().drawImage(new GreenfootImage("$5000", 20, Color.BLACK, null), 680, 80);
getBackground().drawImage(new GreenfootImage("$3500", 20, Color.BLACK, null), 680, 200);
getBackground().drawImage(new GreenfootImage("$500", 20, Color.BLACK, null), 680, 320);
getBackground().drawImage(new GreenfootImage("+10hp, $500", 20, Color.BLACK, null), 660, 490);
getBackground().drawImage(new GreenfootImage("Welcome hero! \n Come and spend your cash!", 20, Color.BLUE, null), 40, 300);
prepare();
}
public void act()
{
next();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Buy buy = new Buy();
addObject(buy,693,535);
Buy buy2 = new Buy();
addObject(buy2,702,377);
Buy buy3 = new Buy();
addObject(buy3,703,249);
Buy buy4 = new Buy();
addObject(buy4,702,127);
}
public void next()
{
back.nextLevel();
myWorld.currentLevel = 2;
}
}
