Move GameOver check into Level.

This commit is contained in:
Jan Philipp Timme 2014-11-25 10:54:20 +01:00
parent d64eff31e0
commit af5bc93004
2 changed files with 19 additions and 3 deletions

View File

@ -1,7 +1,15 @@
package de.teamteamteam.spacescooter.level; package de.teamteamteam.spacescooter.level;
import de.teamteamteam.spacescooter.screen.GameScreen;
import de.teamteamteam.spacescooter.utility.Loader; import de.teamteamteam.spacescooter.utility.Loader;
/**
* Implementation of the actual level based gameplay logic.
* This guy takes care of building up the basics at the very beginning,
* spawning all the entities in the right moments, doing logic concerning whether
* the game is over or not and other "event"-based stuff that can be configured in the
* Levelconfig.
*/
public final class Level { public final class Level {
/** /**
@ -30,4 +38,12 @@ public final class Level {
} }
/**
* Tell whether the Game is over or not.
* Evaluates things like whether the Player is alive or
* - if there is a bossfight - if the boss is dead.
*/
public boolean isGameOver() {
return !GameScreen.getPlayer().isAlive();
}
} }

View File

@ -76,8 +76,7 @@ public class GameScreen extends Screen {
/** /**
* Trigger level logic, trigger updates on all entities, * Trigger level logic, trigger updates on all entities,
* take care of user input such as pressing escape and * take care of user input such as pressing escape and
* do a little(!) check on the gameover condition. * do a little check on the gameover condition.
* TODO: Let the level take care of that.
*/ */
@Override @Override
protected void update() { protected void update() {
@ -94,7 +93,8 @@ public class GameScreen extends Screen {
if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
this.setOverlay(new GamePausedScreen(this)); this.setOverlay(new GamePausedScreen(this));
} }
if (!GameScreen.player.isAlive()) { //The level shall take this over. //Go to GameOverScreen if the game is actually over.
if (this.level.isGameOver()) {
this.parent.setOverlay(new GameOverScreen(this.parent)); this.parent.setOverlay(new GameOverScreen(this.parent));
} }
} }