Ok, I've got 4 images of hearts. One with 3 one with 2, 1, 0. I want to make it so that when the variable "health" is at 1 it shows 1 heart, when at 2 it shows 2 hearts,etc. How would I do this?
GreenfootImage[] hearts = { new GreenfootImage("no_hearts.jpg"),
new GreenfootImage("one_heart.jpg"),
new GreenfootImage("two_hearts.jpg"),
new GreenfootImage("three_hearts.jpg") }
int health = 3;
private void updateImage()
{
setImage(hearts[health]);
}public Hearts()
{
updateImage();
}public void adjustHearts(int adjustmentValue)
{
health += adjustmentValue;
if (health > 3) health = 3;
if (health == 0) Greenfoot.stop();
else updateImage();
}addObject(hearts, x, y);
public Hearts hearts = new Hearts();
WorldSubClass worldsubclass = (WorldSubClass) getWorld(); worldsubclass.hearts.adjustHearts(-1);