diff --git a/core/src/com/me/pacman/state/PlayState.java b/core/src/com/me/pacman/state/PlayState.java index fc673be..8082c1c 100644 --- a/core/src/com/me/pacman/state/PlayState.java +++ b/core/src/com/me/pacman/state/PlayState.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.me.pacman.PacDude; +import com.me.pacman.Score; import com.me.pacman.Sound; import com.me.pacman.entity.*; import com.me.pacman.entity.ai.ReturnToBase; @@ -50,6 +51,7 @@ public class PlayState extends LevelState { public boolean hasDied; private int score; + private int highScore; private int lives; public int round; private boolean paused = false; @@ -125,6 +127,7 @@ public class PlayState extends LevelState { } private void setGameState(GameState state) { + if (state == null) return; this.state = state; this.stateTimer = state.timer; } @@ -183,6 +186,10 @@ public class PlayState extends LevelState { private void preNewGame() { score = 0; + + Score hs = game.highScores.getCurrentHighScore(); + highScore = hs == null ? 0 : hs.score; + lives = 3; round = 0; @@ -241,7 +248,10 @@ public class PlayState extends LevelState { newRound(); return GameState.NEW_ROUND_WAIT; case GAME_OVER: - preNewGame(); + if (score > highScore) { + game.setNextState(new HighScoreEntryState(game, new Score("aaa", score))); + return null; + } return GameState.PRE_NEW_GAME; case GHOST_CAUGHT_POINTS_WAIT: updateBackgroundAudio(); @@ -262,12 +272,12 @@ public class PlayState extends LevelState { // Draw score // Determine x position based on score size. - int scoreTileX = 5 - (score > 0 ? (int) Math.log10(score) - 1 : 0); - game.fontRenderer.draw(game.batch, score > 0 ? "" + score : "00", scoreTileX * 8, 34 * 8); + String s = score > 0 ? Integer.toString(score) : "00"; + game.fontRenderer.draw(game.batch, s, (7 - s.length()) * 8, 34 * 8); // Draw high score game.fontRenderer.draw(game.batch, "high score", 9 * 8, 35 * 8); - game.fontRenderer.draw(game.batch, "10000", 12 * 8, 34 * 8); + game.fontRenderer.draw(game.batch, score >= highScore? s : Integer.toString(highScore), 12 * 8, 34 * 8); // Draw remaining lives for (int i = 0; i < lives; i++) {