hello. i want to make a lives timer so that when an asteroid hits earth, earth loses a life until it reacher zero, then Greenfoot should stop. any advise?
private int lives;
public Space()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(1050, 400, 1);
prepare();
score = 0;
showScore();
time = 2000;
showTime();
lives = 3;
showLives();
}
/**
* If an Asteroid hits Earth, remove life until 0
*/
private void removeLives()
{
lives--;
showLives();
if( lives == 0 )
{
Greenfoot.stop();
showEndMessage();
}
}
private void showLives()
{
showText("Lives:" + lives, 400, 350);
} if(isTouching(BigAsteroid.class))
{
Space space = (Space)getWorld();
space.removeLives();
removeTouching(BigAtseroid.class);
}/**
* If an Asteroid hits Earth, remove life until 0
*/
public void removeLives()
{
lives--;
showLives();
if( lives == 0 )
{
Greenfoot.stop();
showEndMessage();
}
}