I am trying to make my main actor, a bear, of the game disappear after a health bar becomes empty. Although I do remove the object of the bear, I do not know how to make the bear stop its act method as soon as the gameover object appears.
public void act() {
if (Greenfoot.isKeyDown("up"))
{
setRotation(270);
move(5);
checkObstacle();
consume();
}
if (Greenfoot.isKeyDown("down")) {
setRotation(90);
move(5);
checkObstacle();
consume();
}
if (Greenfoot.isKeyDown("left")) {
setRotation(180);
move(5);
checkObstacle();
consume();
}
if (Greenfoot.isKeyDown("right")) {
setRotation(0);
move(5);
checkObstacle();
consume();
}
}
public void checkObstacle()
{ Actor rock = getOneIntersectingObject(Rock.class);
if(rock != null)
{
World myWorld = getWorld();
ExampleWorld exampleworld = (ExampleWorld)myWorld;
HealthBar healthbar = exampleworld.getHealthBar();
if(touchingRock == false){
healthbar.loseHealthRock();
touchingRock = true;
if(healthbar.health<=0){
myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2);
myWorld.removeObject(this);
}
}
}
else{
touchingRock = false;
}
}


