Removed static fields in Game state.
Mostly merged from #8 (72e8a7e). Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -66,6 +66,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||
private StateBasedGame game;
|
||||
private Input input;
|
||||
private int state;
|
||||
private Game gameState;
|
||||
|
||||
public GamePauseMenu(int state) {
|
||||
this.state = state;
|
||||
@@ -76,20 +77,21 @@ public class GamePauseMenu extends BasicGameState {
|
||||
throws SlickException {
|
||||
this.container = container;
|
||||
this.game = game;
|
||||
input = container.getInput();
|
||||
this.input = container.getInput();
|
||||
this.gameState = (Game) game.getState(Opsu.STATE_GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
||||
throws SlickException {
|
||||
// background
|
||||
if (Game.getRestart() != Game.RESTART_LOSE)
|
||||
if (gameState.getRestart() != Game.RESTART_LOSE)
|
||||
GameImage.PAUSE_OVERLAY.getImage().draw();
|
||||
else
|
||||
GameImage.FAIL_BACKGROUND.getImage().draw();
|
||||
|
||||
// draw buttons
|
||||
if (Game.getRestart() != Game.RESTART_LOSE)
|
||||
if (gameState.getRestart() != Game.RESTART_LOSE)
|
||||
continueButton.draw();
|
||||
retryButton.draw();
|
||||
backButton.draw();
|
||||
@@ -124,21 +126,21 @@ public class GamePauseMenu extends BasicGameState {
|
||||
switch (key) {
|
||||
case Input.KEY_ESCAPE:
|
||||
// 'esc' will normally unpause, but will return to song menu if health is zero
|
||||
if (Game.getRestart() == Game.RESTART_LOSE) {
|
||||
if (gameState.getRestart() == Game.RESTART_LOSE) {
|
||||
MusicController.stop();
|
||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
} else {
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
Game.setRestart(Game.RESTART_FALSE);
|
||||
gameState.setRestart(Game.RESTART_FALSE);
|
||||
game.enterState(Opsu.STATE_GAME);
|
||||
}
|
||||
break;
|
||||
case Input.KEY_R:
|
||||
// restart
|
||||
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
|
||||
Game.setRestart(Game.RESTART_MANUAL);
|
||||
gameState.setRestart(Game.RESTART_MANUAL);
|
||||
game.enterState(Opsu.STATE_GAME);
|
||||
}
|
||||
break;
|
||||
@@ -153,7 +155,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||
if (button == Input.MOUSE_MIDDLE_BUTTON)
|
||||
return;
|
||||
|
||||
boolean loseState = (Game.getRestart() == Game.RESTART_LOSE);
|
||||
boolean loseState = (gameState.getRestart() == Game.RESTART_LOSE);
|
||||
|
||||
// if music faded out (i.e. health is zero), don't process any actions before FADEOUT_TIME
|
||||
if (loseState && System.currentTimeMillis() - pauseStartTime < FADEOUT_TIME)
|
||||
@@ -161,11 +163,11 @@ public class GamePauseMenu extends BasicGameState {
|
||||
|
||||
if (continueButton.contains(x, y) && !loseState) {
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
Game.setRestart(Game.RESTART_FALSE);
|
||||
gameState.setRestart(Game.RESTART_FALSE);
|
||||
game.enterState(Opsu.STATE_GAME);
|
||||
} else if (retryButton.contains(x, y)) {
|
||||
SoundController.playSound(SoundEffect.MENUHIT);
|
||||
Game.setRestart(Game.RESTART_MANUAL);
|
||||
gameState.setRestart(Game.RESTART_MANUAL);
|
||||
game.enterState(Opsu.STATE_GAME);
|
||||
} else if (backButton.contains(x, y)) {
|
||||
MusicController.pause(); // lose state
|
||||
@@ -179,7 +181,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||
public void enter(GameContainer container, StateBasedGame game)
|
||||
throws SlickException {
|
||||
pauseStartTime = System.currentTimeMillis();
|
||||
if (Game.getRestart() == Game.RESTART_LOSE) {
|
||||
if (gameState.getRestart() == Game.RESTART_LOSE) {
|
||||
MusicController.fadeOut(FADEOUT_TIME);
|
||||
SoundController.playSound(SoundEffect.FAIL);
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user