Maybe the value of 'isInvincible' should be governed by both whether intersecting a spacedog or a boss. That is, instead of two different collision methods (one for spacedog and one for boss -- where the second one will always determine the final value of 'isInvincible'), combine them into one method:
private void checkCollision()
{
Space space = (Space) getWorld();
if (space == null) return;
Actor a = getOneIntersectingObject(Boss.class);
Actor b = getOneIntersectingObject(Spacedog.class);
if (a != null || b != null)
{
if (isInvincible) return;
lives--;
counter.loseLife();
Greenfoot.playSound("catscreech2.wav");
space.addObject(new Explosion(), getX(), getY());
space.removeObject(this);
if (lives <= 0)
{
space.addObject(new GameOver(), space.getWidth()/2, space.getHeight()/2);
}
else
{
space.addObject(new Rocket(), 65, 413);
space.addObject(this, 65, 413);
isInvincible = true;
movement.setNeutral();
}
}
else
{
isInvincible = false;
}
}
