Register high score if it fits anywhere in the top 10.
When adding it, render in appropriate position.
This commit is contained in:
parent
5645b4bcf5
commit
fc912863ad
@ -18,6 +18,7 @@ public class HighScoreEntryState extends State {
|
|||||||
private Texture background;
|
private Texture background;
|
||||||
private Score score;
|
private Score score;
|
||||||
|
|
||||||
|
private final int position;
|
||||||
private int currLetter;
|
private int currLetter;
|
||||||
private char[] name;
|
private char[] name;
|
||||||
|
|
||||||
@ -26,8 +27,9 @@ public class HighScoreEntryState extends State {
|
|||||||
|
|
||||||
private boolean buttonPressed;
|
private boolean buttonPressed;
|
||||||
|
|
||||||
public HighScoreEntryState(PacDude game, Score score) {
|
public HighScoreEntryState(PacDude game, Score score, int position) {
|
||||||
super(game);
|
super(game);
|
||||||
|
this.position = position;
|
||||||
this.score = score;
|
this.score = score;
|
||||||
this.currLetter = 0;
|
this.currLetter = 0;
|
||||||
this.flash = false;
|
this.flash = false;
|
||||||
@ -51,17 +53,22 @@ public class HighScoreEntryState extends State {
|
|||||||
game.fontRenderer.setColor(Color.CHARTREUSE);
|
game.fontRenderer.setColor(Color.CHARTREUSE);
|
||||||
game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE);
|
game.fontRenderer.draw(game.batch, "score name", (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 22 * Constants.TILE_SIZE);
|
||||||
|
|
||||||
game.fontRenderer.setColor(Color.BLUE);
|
|
||||||
game.fontRenderer.draw(game.batch, "" + score.score, (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, 18 * 9);
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * Constants.TILE_SIZE + Constants.TILE_SIZE/2, 18 * 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
game.fontRenderer.setColor(Color.WHITE);
|
|
||||||
Score[] scores = game.highScores.getHighScores(9);
|
Score[] scores = game.highScores.getHighScores(9);
|
||||||
for (int i = 0; i < scores.length; i++) {
|
for (int n = 0; n < scores.length + 1; n++) {
|
||||||
Score score = scores[i];
|
int y = (18 - n) * 9;
|
||||||
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (17 - i) * 9);
|
|
||||||
|
if (n == position) {
|
||||||
|
game.fontRenderer.setColor(Color.BLUE);
|
||||||
|
game.fontRenderer.draw(game.batch, "" + score.score, (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, y);
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
game.fontRenderer.draw(game.batch, String.valueOf((i == currLetter && flash)? '_' : name[i]), (16 + i) * Constants.TILE_SIZE + Constants.TILE_SIZE/2, y);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Score score = scores[n > position? n - 1 : n];
|
||||||
|
game.fontRenderer.setColor(Color.WHITE);
|
||||||
|
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
||||||
|
@ -200,6 +200,28 @@ public class PlayState extends LevelState {
|
|||||||
pacman.moving = true;
|
pacman.moving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GameState endGame() {
|
||||||
|
Score[] scores = game.highScores.getHighScores(10);
|
||||||
|
|
||||||
|
boolean addToScores = scores.length < 10;
|
||||||
|
int scorePosition = scores.length;
|
||||||
|
|
||||||
|
for (int i = 0; i < scores.length; i++) {
|
||||||
|
if (score > scores[i].score) {
|
||||||
|
addToScores = true;
|
||||||
|
scorePosition = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addToScores) {
|
||||||
|
game.setNextState(new HighScoreEntryState(game, new Score("aaa", score), scorePosition));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GameState.PRE_NEW_GAME;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
levelBackground = game.assets.getLevelBackground();
|
levelBackground = game.assets.getLevelBackground();
|
||||||
@ -227,12 +249,7 @@ public class PlayState extends LevelState {
|
|||||||
newRound();
|
newRound();
|
||||||
return GameState.NEW_ROUND_WAIT;
|
return GameState.NEW_ROUND_WAIT;
|
||||||
case GAME_OVER:
|
case GAME_OVER:
|
||||||
if (score > highScore) {
|
return endGame();
|
||||||
game.setNextState(new HighScoreEntryState(game, new Score("aaa", score)));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
preNewGame();
|
|
||||||
return GameState.PRE_NEW_GAME;
|
|
||||||
case GHOST_CAUGHT_POINTS_WAIT:
|
case GHOST_CAUGHT_POINTS_WAIT:
|
||||||
updateBackgroundAudio();
|
updateBackgroundAudio();
|
||||||
return GameState.PLAYING;
|
return GameState.PLAYING;
|
||||||
|
Loading…
Reference in New Issue
Block a user