SO my game is almost done , I jut need to know how to add a visual life counter for the princess so that the player can monitor their lives. ( My game is a tower defense game btw and the princess will be the one getting hit) . Where do I put the code for that string (if I'm not mistaken. Attached are the my world codes and the princess codes for her life.
For the princess :
public MyWorld()
{
super(1000, 700, 1);
setBackground("bg2.jpg");
addObject(new Princess(), 352,594);
addObject(new Infantry(), 344,309);
addObject(new arm(), 369,331);
}
public void act()
{
if(Greenfoot.getRandomNumber(100)<1)
{
addObject(new Enemy(), 999, 594);
}
}
}
public class Princess extends Actor
{
public int life = 20;
public Princess()
{
GreenfootImage image = getImage();
image.scale(75, 100);
setImage(image);
}
public void act()
{
if (getOneIntersectingObject(Enemy.class) != null) {
life--;
removeTouching(Enemy.class);
if(life==0)
Greenfoot.setWorld(new GameOver());
}
}
}
