Same thing
checkLife();
public void checkLife()
{
int lives = Hero.getLives();
if (lives == 4) removeObject(life4);
if (lives == 3) removeObject(life3);
if (lives == 2) removeObject(life2);
if (lives == 1) removeObject(life1);
if (lives == 0) removeObject(life0);
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The parent class of worlds
*
* @soumya.__.khanna (Soumya Khanna)
* @I'llLookItUp (Jun 17th, 2020)
*/
public class Worlds extends World
{
public int width = getWidth(); //Width of the world --Accessed in children classes
public static Hero mario = new Hero(); //Declaring the Swimming Mario Class
//Number of hearts based on the life of Mario
public Life life0;
public Life life1;
public Life life2;
public Life life3;
public Life life4;
public Score score; //Adding the score board
public void act()
{
checkLife();
}
public Worlds()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(2200, 576, 1, false);
}
public void lifeCounter(int x, int y)
{
//Declaring all lives
life0 = new Life();
life1 = new Life();
life2 = new Life();
life3 = new Life();
life4 = new Life();
//Adding lifes evenly spaced around
addObject(life0, x, y);
addObject(life1, x + 30, y);
addObject(life2, x + 60, y);
addObject(life3, x + 90, y);
addObject(life4, x + 120, y);
}
public void checkLife()
{
int lives = Hero.getLives();
if (lives == 4) removeObject(life4);
if (lives == 3) removeObject(life3);
if (lives == 2) removeObject(life2);
if (lives == 1) removeObject(life1);
if (lives == 0) removeObject(life0);
}
public Score getScore()
{
return score; //Information from scoreboard
}
}