how do you have lifes


public void act() { if(!isDead) { //if the player is not dead... the player can continue to act //put your original act method here! } else { //if the player has lost a life... timeToRegenerate++; getImage().setTransparency(0); //make the player invisible when dead if(timeToRegenerate > 30) { //if the player has been dead long enough, isDead = false; //regenerate! timeToRegenerate = 0; getImage().setTransparency(255); setLocation(someX, someY); //where someX and someY are the } //the location you want the player to regenerate at. } }
private int lives = 5; public void act() { if(!isDead) { //if the player is not dead... the player can continue to act //put your original act method here! } else { //if the player has lost a life... if(lives > 0) { timeToRegenerate++; getImage().setTransparency(0); //make the player invisible when dead if(timeToRegenerate > 30) { //if the player has been dead long enough, isDead = false; //regenerate! timeToRegenerate = 0; lives--; getImage().setTransparency(255); setLocation(someX, someY); //where someX and someY are the } //the location you want the player to regenerate at. } else { getWorld().removeObject(this); //die. add whatever extra code you want here. } } }
private boolean isDead = false; private int timeToRegenerate = 0;