From eeb2a9c87527f49de39bfcd0113ac3e5616224dd Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 2 Dec 2014 12:01:18 +0100 Subject: [PATCH] Implement a delay on game over, so the player can explode properly and stuff. --- .../spacescooter/entity/Player.java | 2 + .../spacescooter/level/Level.java | 57 +++++++++++++++---- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index c979bf0..0e5c46a 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -9,6 +9,7 @@ import de.teamteamteam.spacescooter.brain.PlayerSession; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.KeyboardListener; import de.teamteamteam.spacescooter.entity.enemy.Enemy; +import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion; import de.teamteamteam.spacescooter.entity.obstacle.Obstacle; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; @@ -150,6 +151,7 @@ public class Player extends ShootingEntity implements KeyboardListener { @Override public void explode() { SoundSystem.playSound("sounds/abgang.wav"); + new MultiExplosion(this.getCenteredX(), this.getCenteredY()); } /** diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index 7ebcb7c..bb0ba42 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -41,12 +41,25 @@ public final class Level { */ private Thread backgroundMusic; + /** + * Indicator whether the game is over. + * This will be updated within handleUpdateTick() and helper methods. + */ + private boolean isGameOver; + + /** + * A counter determining the amount of time to wait before revealing + * that the game is over (meaning isGameOver() returning true). + */ + private int gameOverDelay; /** * Constructor creating a LevelConfig based on a given config file. */ public Level(String levelConfig) { this.levelClock = 0; + this.isGameOver = false; + this.gameOverDelay = 3; this.config = Loader.getLevelConfigByFilename(levelConfig); } @@ -98,17 +111,47 @@ public final class Level { } } } + + //Check for GameOver things. + this.checkGameOverCondition(); + + //Apply the gameOverDelay if game is already over. + if(this.isGameOver && this.gameOverDelay > 0) { + this.gameOverDelay--; + } + //Increase levelClock this.levelClock++; } /** - * 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. */ + private void checkGameOverCondition() { + if(!GameScreen.getPlayer().isAlive()) { + this.isGameOver = true; + } + } + + /** + * Tell whether the Game is over or not. + * Takes into account the delay, so a player can properly explode. + */ public boolean isGameOver() { - return !GameScreen.getPlayer().isAlive(); + return (this.gameOverDelay == 0); + } + + + /** + * Clean up before the Level is torn down. + * Stop the music, ... + */ + public void tearDown() { + if(this.backgroundMusic != null) { + this.backgroundMusic.interrupt(); + this.backgroundMusic = null; + } } /** @@ -150,14 +193,4 @@ public final class Level { } } - /** - * Clean up before the Level is torn down. - * Stop the music, ... - */ - public void tearDown() { - if(this.backgroundMusic != null) { - this.backgroundMusic.interrupt(); - this.backgroundMusic = null; - } - } }