Adding of new high scores + displaying of actual high score

This commit is contained in:
Matt Low 2020-01-16 16:40:09 +04:00
parent a9e99a363c
commit 0a058e3d19

View File

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