Hi. So i'm having this poblem implementing a multiple lives system into the game i'm making.
Right now, if tested, the game spawns infinite amounts of soviet soldiers, and the troopcounter variable doesn't seem to be updating, when there should only be 5 soviet soldiers available for spawning
private int troopcounter = 5;
public void die()
{
if (canSee (Player2Bullet.class))
{
eat (Player2Bullet.class);
Greenfoot.playSound ("wilhelm.wav");//plays whilhelm scream on death
getWorld().addObject (new DeadSoviet(), getX(), getY()+20);//adds a new actor with image of a dead Soviet soldier
getWorld().addObject (new Player1(), 55, 230);//adds new soldier to the game
getWorld().removeObject(this);//removes old character from the game
troopcounter--; //decreases number of troops available by one
if (troopcounter == 0)//enemy side wins if all available troops are dead
{
Greenfoot.setWorld(new AxisWin());
}
}
else if (canSee (Grenade2.class))
{
getWorld().addObject (new DeadSoviet(), getX(), getY()+20);
Greenfoot.playSound ("wilhelm.wav");
getWorld().addObject (new Player1(), 55, 230);
getWorld().removeObject(this);
troopcounter--;
if (troopcounter == 0)
{
Greenfoot.setWorld(new AxisWin());
}
}
}
