I was trying to get a healthbar on greenfoot but i cant find out whats the error in my code
this is the code elephant
and this is the code in MyWorld
public class MyWorld extends World
{
HealthBar healthbar = new HealthBar();
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
super(1000, 800, 1);
populateWorld();
}
public HealthBar getHealthBar()
{
return healthbar;
}
public void populateWorld()
{
addObject(new elephant(), 300, 300);
addObject(new HealthBar(),100,40);
addObject(new Mouse(), 90, 70);
addObject(new Mouse(), 390, 200);
addObject(new Mouse(), 360, 500);
}
}
public void hitMouse()
{
Actor Mouse = getOneIntersectingObject(Mouse.class);
if (Mouse !=null)
{
World myWorld = getWorld();
MyWorld myworld = (MyWorld) myWorld;
HealthBar healthbar = MyWorld.getHealthBar();
if (touchingMouse == true )
{
health--;
touchingMouse = true;
if (healthbar.getHealth() <=0)
{
getWorld().removeObject(this);
}
}
}
}


