I have this so far, but it doesn't seem to run the gameOver() class correctly. The gameOver() class is last in my act method, just after kill(), if it matters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public void kill() { //detects when the gun is close to an asteroid and shoots removes them both List<Enemy1> enemies = new ArrayList<Enemy1>(); enemies = this.getObjectsInRange(25, Enemy1.class); for (Enemy1 e : enemies) { if (enemies.size()>0) { dead = true; getWorld().removeObject(enemies.get(0)); getWorld().removeObject(this); } } } public void gameOver() { if (dead == true){ getWorld().removeObjects(getWorld().getObjects(null)); getWorld().addObject(new GameOver(), 300, 200); Greenfoot.stop(); } } |
