Removed static fields in Game state.

Mostly merged from #8 (72e8a7e).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-14 23:57:50 -05:00
parent 64d961a8f9
commit 03095733df
5 changed files with 36 additions and 33 deletions

View File

@ -250,11 +250,10 @@ public class GameScore {
/**
* Loads all game score images.
* @param dir the image directory
* @throws SlickException
*/
public void loadImages() throws SlickException {
File dir = MusicController.getOsuFile().getFile().getParentFile();
public void loadImages(File dir) throws SlickException {
// combo burst images
if (comboBurstImages != null) {
for (int i = 0; i < comboBurstImages.length; i++) {

View File

@ -68,9 +68,9 @@ public class Game extends BasicGameState {
RESTART_LOSE = 3; // health is zero: no-continue/force restart
/**
* Current restart state.
* Minimum time before start of song, in milliseconds, to process skip-related actions.
*/
private static byte restart;
private static final int SKIP_OFFSET = 2000;
/**
* The associated OsuFile object.
@ -80,7 +80,7 @@ public class Game extends BasicGameState {
/**
* The associated GameScore object (holds all score data).
*/
private static GameScore score;
private GameScore score;
/**
* Current hit object index in OsuHitObject[] array.
@ -117,6 +117,11 @@ public class Game extends BasicGameState {
*/
private int[] hitResultOffset;
/**
* Current restart state.
*/
private byte restart;
/**
* Current break index in breaks ArrayList.
*/
@ -137,11 +142,6 @@ public class Game extends BasicGameState {
*/
private MenuButton skipButton;
/**
* Minimum time before start of song, in milliseconds, to process skip-related actions.
*/
private static final int SKIP_OFFSET = 2000;
/**
* Current timing point index in timingPoints ArrayList.
*/
@ -222,6 +222,7 @@ public class Game extends BasicGameState {
// create the associated GameScore object
score = new GameScore(width, height);
((GameRanking) game.getState(Opsu.STATE_GAMERANKING)).setGameScore(score);
// playfield background
try {
@ -874,7 +875,7 @@ public class Game extends BasicGameState {
// load other images...
((GamePauseMenu) game.getState(Opsu.STATE_GAMEPAUSEMENU)).loadImages();
score.loadImages();
score.loadImages(osu.getFile().getParentFile());
}
/**
@ -943,13 +944,8 @@ public class Game extends BasicGameState {
/**
* Sets/returns whether entering the state will restart it.
*/
public static void setRestart(byte restart) { Game.restart = restart; }
public static byte getRestart() { return Game.restart; }
/**
* Returns the associated GameScore object.
*/
public static GameScore getGameScore() { return score; }
public void setRestart(byte restart) { this.restart = restart; }
public byte getRestart() { return restart; }
/**
* Returns whether or not the track is in the lead-in time state.

View File

@ -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

View File

@ -75,8 +75,6 @@ public class GameRanking extends BasicGameState {
this.game = game;
this.input = container.getInput();
score = Game.getGameScore();
int width = container.getWidth();
int height = container.getHeight();
@ -170,7 +168,7 @@ public class GameRanking extends BasicGameState {
if (retryButton.contains(x, y)) {
OsuFile osu = MusicController.getOsuFile();
Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString()));
Game.setRestart(Game.RESTART_MANUAL);
((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.RESTART_MANUAL);
SoundController.playSound(SoundEffect.MENUHIT);
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} else if (exitButton.contains(x, y)) {
@ -192,4 +190,12 @@ public class GameRanking extends BasicGameState {
Utils.getBackButton().setScale(1f);
SoundController.playSound(SoundEffect.APPLAUSE);
}
/**
* Sets the associated GameScore object.
* @param score the GameScore
*/
public void setGameScore(GameScore score) {
this.score = score;
}
}

View File

@ -712,7 +712,7 @@ public class SongMenu extends BasicGameState {
Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString()));
OsuParser.parseHitObjects(osu);
HitSound.setSampleSet(osu.sampleSet);
Game.setRestart(Game.RESTART_NEW);
((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.RESTART_NEW);
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
}