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?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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 ); } |
1 2 3 4 5 6 | if (isTouching(BigAsteroid. class )) { Space space = (Space)getWorld(); space.removeLives(); removeTouching(BigAtseroid. class ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * If an Asteroid hits Earth, remove life until 0 */ public void removeLives() { lives--; showLives(); if ( lives == 0 ) { Greenfoot.stop(); showEndMessage(); } } |