So I have a shop that I am trying to make work, I can switch between worlds just fine but I realized that when I would switch back to the main world it would reset everything (the characters' positions and all the variables). I can't figure out a way to make all the stuff spawn in and all the variables reset only the 1st time the world is "spawned in". Any help would be greatly appreciated.
import greenfoot.*;
import javax.swing.JOptionPane;
/**
* You are the Human, the last survivor of the zombie apocalypse. In This level you are at your home camp and you are under attack! Fend off the impending horde for as long as possible and mabye survive for another day
*
* @author Eric Faltermeier
* @date 12/4/2017
*
* I got the picure of grass from Textures101.com
*/
public class ZombieWorld extends World
{
public ZombieWorld()
{
super(1600, 900, 1);
showInstructions();
prepare();
}
public void prepare()
// This is where all the objects are added, a human, a test variable, 5 zombies on the left side, and 5 zombies on the right side
{
addObject(new TestVariable(), 800, 450);
addObject(new Human(), 800, 450);
addObject(new BulletCount(), 1530, 20);
addObject(new Money(), 1417, 20);
for(int c = 0; c < 5; c++)
{
int x = getWidth();
int y = Greenfoot.getRandomNumber(getHeight());
addObject(new Zombie(), x, y);
}
for(int c = 0; c < 5; c++)
{
int x = 0;
int y = Greenfoot.getRandomNumber(getHeight());
addObject(new Zombie(), x, y);
}
}
public void showInstructions()
// At the beginning of the game this shows up, it tells the player the goal and how to play
{
JOptionPane.showMessageDialog(null, "You are the last Human alive and you have to survive!\nUse WSAD to move around and space bar to shoot");
}
}
