I also removed the isInvincible call in my act method completely if that matters.


private void checkBossCollision() { if (getWorld() == null) return; Actor a = getOneIntersectingObject(Boss.class); if (a != null) { if (isInvincible) return; lives--; counter.loseLife(); Greenfoot.playSound("catscreech2.wav"); Space space = (Space) getWorld(); space.addObject(new Explosion(), getX(), getY()); space.removeObject(this); if (lives <= 0){ GameOver gameover = new GameOver(); space.addObject(gameover, space.getWidth()/2, space.getHeight()/2); } else { int x = Greenfoot.getRandomNumber(340); space.addObject(new Rocket(), 65, 413); space.addObject(this, 65, 413); isInvincible = true; movement.setNeutral(); List<Boss> bosses = getNeighBours(something, true, Boss.class); for (int i = 0; i < bosses.size(); i ++) { Boss boss = (Boss)bosses.get(i); if (boss.getX() > getX()) { boss.setLocation(boss.getX() + something, boss.getY()); } else { boss.setLocation(boss.getX() - something, boss.getY()); } if (boss.getY() > getY()) { boss.setLocation(boss.getX(), boss.getY() + something); } else { boss.setLocation(boss.getX(), boss.getY() - something); } } } } else { isInvincible = false; }
private void checkBossCollision() { if (getWorld() == null) return; Actor a = getOneIntersectingObject(Boss.class); if (a != null) { if (isInvincible) return; lives--; counter.loseLife(); Greenfoot.playSound("catscreech2.wav"); Space space = (Space) getWorld(); space.addObject(new Explosion(), getX(), getY()); space.removeObject(this); if (lives <= 0){ GameOver gameover = new GameOver(); space.addObject(gameover, space.getWidth()/2, space.getHeight()/2); } else { int x = Greenfoot.getRandomNumber(340); space.addObject(new Rocket(), 65, 413); space.addObject(this, 65, 413); isInvincible = true; movement.setNeutral(); List<Boss> bosses = getNeighbors(25, true, Boss.class); for (int i = 0; i < bosses.size(); i ++) { Boss boss = (Boss)bosses.get(i); if (boss.getX() > getX()) { boss.setLocation(boss.getX() + 25, boss.getY()); } else { boss.setLocation(boss.getX() - 25, boss.getY()); } if (boss.getY() > getY()) { boss.setLocation(boss.getX(), boss.getY() + 25); } else { boss.setLocation(boss.getX(), boss.getY() - 25); } } } } else { isInvincible = false; } }
private void checkBossCollision() { if (getWorld() == null) return; Actor a = getOneIntersectingObject(Boss.class); if (a != null) { if (isInvincible) return; lives--; counter.loseLife(); Greenfoot.playSound("catscreech2.wav"); Space space = (Space) getWorld(); space.addObject(new Explosion(), getX(), getY()); getImage().setTransparency(0); isInvincible = true; if (lives <= 0){ GameOver gameover = new GameOver(); space.addObject(gameover, space.getWidth()/2, space.getHeight()/2); } else { int x = Greenfoot.getRandomNumber(340); space.addObject(new Rocket(), 65, 413); getImage().setTransparency(255); movement.setNeutral(); List<Boss> bosses = getNeighbours(25, true, Boss.class); for (int i = 0; i < bosses.size(); i ++) { Boss boss = (Boss)bosses.get(i); if (boss.getX() > getX()) { boss.setLocation(boss.getX() + 25, boss.getY()); } else { boss.setLocation(boss.getX() - 25, boss.getY()); } if (boss.getY() > getY()) { boss.setLocation(boss.getX(), boss.getY() + 25); } else { boss.setLocation(boss.getX(), boss.getY() - 25); } } } } else { isInvincible = false; } }