I have a basic health code but i need help with a counter and if it touches an actor to decrease
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
* Write a description of class HealthBar here.
*
* @author (your name)
* @version (a version number or a date)
*
*/
public class health extends Soul
{
boolean inPosition = false;
int health;
int width=80;
int height=15;
int healthPerPixel;
public health(int hp)
{
health=hp;
healthPerPixel=(int)(width/health); update();
}
public void act()
{
}
public void update()
{
setImage(new GreenfootImage(width+2,height+2));
GreenfootImage h=getImage();
h.setColor(Color.BLACK);
h.drawRect(0,0,width+1,height+1);
h.setColor(Color.GREEN);
h.fillRect(1,1,health*healthPerPixel,height);
}
public void loseHealth()
{
//health=health-tower.dmg;
update();
}
}

