When my Health Bar is empty I want my Game Over Actor for appear, how do I do this??
public class HealthBar extends Actor
{
int health = 10;
int healthBarWidth = 80;
int healthBarHeight = 15;
int pixelsPerHealthPoint = (int)healthBarWidth/health;
/**
* Act - do whatever the HealthBar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public HealthBar()
{
update();
}
public void act()
{
update();
}
public void update()
{
setImage(new GreenfootImage(healthBarWidth + 2, healthBarHeight + 2));
GreenfootImage myImage = getImage();
myImage.setColor(Color.WHITE);
myImage.drawRect(0, 0, healthBarWidth + 1, healthBarHeight + 1);
myImage.setColor(Color.RED);
myImage.fillRect(1, 1, health*pixelsPerHealthPoint, healthBarHeight);
}
public void loseHealth()
{
health--;
}
}
public void loseHealth()
{
health--;
update();
if (health<1) getWorld().addObject(new GameOver(),getWorld().getWidth()/2,getWorld().getHeight()/2);
}