public void act()
{
setImage(new GreenfootImage(102, 52));
getImage().drawRect(0,0,51,11);
getImage().setColor(Color.RED);
getImage().fillRect(1,1,health,10);
World world = getWorld();
if (getWorld() instanceof MyWorld){
loseHealthMyWorld();
}
if (getWorld() instanceof HardRoom){
loseHealthMyWorld();
}
}
public void loseHealthMyWorld()
{
if(myWorld.getPlayer().hitByEnemy() == true)
{
health--;
}
else
health = health;
if (health<=0)
{
Greenfoot.stop();
}
}
public void loseHealthHardRoom()
{
if(hardRoom.getPlayer().hitByEnemy())
{
health--;
}
if (health<=0)
{
Greenfoot.stop();
}
} public boolean hitByEnemy()
{
Actor enemy = getOneObjectAtOffset(0,0, ENEMY.class);
Actor slime = getOneObjectAtOffset(0,0, Slime.class);
if(enemy!=null || slime!=null)
{
return true;
}
else
return false;
}
