Implement a delay on game over, so the player can explode properly and stuff.

This commit is contained in:
Jan Philipp Timme 2014-12-02 12:01:18 +01:00
parent beba843420
commit eeb2a9c875
2 changed files with 47 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.control.KeyboardListener; import de.teamteamteam.spacescooter.control.KeyboardListener;
import de.teamteamteam.spacescooter.entity.enemy.Enemy; 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.obstacle.Obstacle;
import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.shot.Shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.entity.spi.Collidable;
@ -150,6 +151,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
@Override @Override
public void explode() { public void explode() {
SoundSystem.playSound("sounds/abgang.wav"); SoundSystem.playSound("sounds/abgang.wav");
new MultiExplosion(this.getCenteredX(), this.getCenteredY());
} }
/** /**

View File

@ -41,12 +41,25 @@ public final class Level {
*/ */
private Thread backgroundMusic; 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. * Constructor creating a LevelConfig based on a given config file.
*/ */
public Level(String levelConfig) { public Level(String levelConfig) {
this.levelClock = 0; this.levelClock = 0;
this.isGameOver = false;
this.gameOverDelay = 3;
this.config = Loader.getLevelConfigByFilename(levelConfig); 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 //Increase levelClock
this.levelClock++; this.levelClock++;
} }
/** /**
* Tell whether the Game is over or not.
* Evaluates things like whether the Player is alive or * Evaluates things like whether the Player is alive or
* - if there is a bossfight - if the boss is dead. * - 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() { 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;
}
}
} }