I have a problem with my little game, if i touch an enemy i get damaged and the healthbar should decrease but it doesn't.
Altough the damaging works, the healthbar doesn't decrease.
Here is my code:
public class HealthBar extends Erm
{
int health = 5;
int healthBarWidth =80;
int healthBarHeight =15;
int pixelsPerHealthPoint = (int) healthBarWidth/health;
public HealthBar () //constructer,runs automatically, creates the healthbar even if the game isnt running
{
update ();
}
/**
* Act - do whatever the HealthBar wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
update ();
}
public void update ()
{
setImage(new GreenfootImage (healthBarWidth + 2, healthBarHeight + 2));
GreenfootImage myImage = getImage();
myImage.setColor(Color.WHITE);
myImage.drawRect(0, 0, healthBarWidth +1, healthBarHeight + 1);
myImage.setColor(Color.RED);
myImage.fillRect(1, 1, health*pixelsPerHealthPoint, healthBarHeight);
}
public void loseHealth ()
{
health --;
}
}
