My game mechanics:
1. When the falling object is on Y(599)/ at the edge, healthbar decreases
please help me make game over screen when the healthbar is empty and also to stop the game.
//this is the code i put in my healthbar actor
//the gameover is an image
public class HealthBar extends Actor
{
int health = 10;
int healthBarWidth= 100;
int healthBarHeight = 15;
int pixelPerHealthPoint = (int)healthBarWidth/health;
public void act(){
}
public HealthBar(){
update();
}
public void update(){
setImage(new GreenfootImage(healthBarWidth + 2, healthBarHeight +2));
GreenfootImage myImage = getImage();
myImage.setColor(greenfoot.Color.WHITE);
myImage.drawRect(0, 0, healthBarWidth + 1, healthBarHeight + 1);
myImage.setColor(greenfoot.Color.GREEN);
myImage.fillRect(1,1, health*pixelPerHealthPoint, healthBarHeight);
}
public int loseHealth(int n){
health = health-n;
update();
return health;
}
public void showGameover(){
if (health == 0)
{
World realWorld = getWorld();
RealGame levelone = (RealGame)realWorld;
gameOver gameover = new gameOver();
realWorld.addObject(gameover, realWorld.getWidth()/5, realWorld.getHeight()/5);
}
}
}Greenfoot.setWorld(new GameOver());