From af5bc93004cff6121c22047d1afae9f6c699c058 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 25 Nov 2014 10:54:20 +0100 Subject: [PATCH] Move GameOver check into Level. --- .../teamteamteam/spacescooter/level/Level.java | 16 ++++++++++++++++ .../spacescooter/screen/GameScreen.java | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index c2b5ca7..c0fda2f 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -1,7 +1,15 @@ package de.teamteamteam.spacescooter.level; +import de.teamteamteam.spacescooter.screen.GameScreen; 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 { /** @@ -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(); + } } diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index c77513e..c11cd62 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -76,8 +76,7 @@ public class GameScreen extends Screen { /** * Trigger level logic, trigger updates on all entities, * take care of user input such as pressing escape and - * do a little(!) check on the gameover condition. - * TODO: Let the level take care of that. + * do a little check on the gameover condition. */ @Override protected void update() { @@ -94,7 +93,8 @@ public class GameScreen extends Screen { if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { 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)); } }