Add visible return/save buttons to high scores pages
This commit is contained in:
parent
1989b4557b
commit
5645b4bcf5
Binary file not shown.
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.2 KiB |
@ -5,11 +5,14 @@ import com.badlogic.gdx.Input;
|
|||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.pacman.Constants;
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.FontRenderer;
|
import com.me.pacman.FontRenderer;
|
||||||
import com.me.pacman.Score;
|
import com.me.pacman.Score;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
|
|
||||||
|
import static com.me.pacman.state.HighScoresState.BUTTON;
|
||||||
|
|
||||||
public class HighScoreEntryState extends State {
|
public class HighScoreEntryState extends State {
|
||||||
|
|
||||||
private Texture background;
|
private Texture background;
|
||||||
@ -21,6 +24,8 @@ public class HighScoreEntryState extends State {
|
|||||||
private boolean flash;
|
private boolean flash;
|
||||||
private float elapsed;
|
private float elapsed;
|
||||||
|
|
||||||
|
private boolean buttonPressed;
|
||||||
|
|
||||||
public HighScoreEntryState(PacDude game, Score score) {
|
public HighScoreEntryState(PacDude game, Score score) {
|
||||||
super(game);
|
super(game);
|
||||||
this.score = score;
|
this.score = score;
|
||||||
@ -58,6 +63,9 @@ public class HighScoreEntryState extends State {
|
|||||||
Score score = scores[i];
|
Score score = scores[i];
|
||||||
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (17 - i) * 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
||||||
|
game.fontRenderer.draw(game.batch, "save", 12 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,6 +82,12 @@ public class HighScoreEntryState extends State {
|
|||||||
Gdx.input.setInputProcessor(null);
|
Gdx.input.setInputProcessor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveScoreAndReturn() {
|
||||||
|
score.scorer = String.valueOf(name);
|
||||||
|
game.highScores.addScore(score);
|
||||||
|
game.setNextState(new HighScoresState(game));
|
||||||
|
}
|
||||||
|
|
||||||
private final class Controller extends InputAdapter {
|
private final class Controller extends InputAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,15 +124,39 @@ public class HighScoreEntryState extends State {
|
|||||||
flash = true;
|
flash = true;
|
||||||
break;
|
break;
|
||||||
case Input.Keys.ENTER:
|
case Input.Keys.ENTER:
|
||||||
score.scorer = String.valueOf(name);
|
case Input.Keys.BACK:
|
||||||
game.highScores.addScore(score);
|
case Input.Keys.ESCAPE:
|
||||||
game.setNextState(new HighScoresState(game));
|
saveScoreAndReturn();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
elapsed = 0f;
|
elapsed = 0f;
|
||||||
return super.keyDown(keycode);
|
return super.keyDown(keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
|
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||||
|
if (BUTTON.contains(coords)) {
|
||||||
|
buttonPressed = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
if (!buttonPressed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
buttonPressed = false;
|
||||||
|
|
||||||
|
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||||
|
if (BUTTON.contains(coords)) {
|
||||||
|
saveScoreAndReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,25 @@ import com.badlogic.gdx.Input;
|
|||||||
import com.badlogic.gdx.InputAdapter;
|
import com.badlogic.gdx.InputAdapter;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.me.pacman.Constants;
|
import com.me.pacman.Constants;
|
||||||
import com.me.pacman.PacDude;
|
import com.me.pacman.PacDude;
|
||||||
import com.me.pacman.Score;
|
import com.me.pacman.Score;
|
||||||
|
|
||||||
public class HighScoresState extends State {
|
public class HighScoresState extends State {
|
||||||
|
|
||||||
|
public static final MenuState.BoundingBox BUTTON = new MenuState.BoundingBox(
|
||||||
|
11 * Constants.TILE_SIZE,
|
||||||
|
5 * Constants.TILE_SIZE,
|
||||||
|
17 * Constants.TILE_SIZE,
|
||||||
|
6 * Constants.TILE_SIZE);
|
||||||
|
|
||||||
|
|
||||||
private Texture background;
|
private Texture background;
|
||||||
|
|
||||||
|
private boolean buttonPressed = false;
|
||||||
|
|
||||||
|
|
||||||
public HighScoresState(PacDude game) {
|
public HighScoresState(PacDude game) {
|
||||||
super(game);
|
super(game);
|
||||||
}
|
}
|
||||||
@ -40,6 +50,9 @@ public class HighScoresState extends State {
|
|||||||
Score score = scores[i];
|
Score score = scores[i];
|
||||||
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (18 - i) * 9);
|
game.fontRenderer.draw(game.batch, String.format("%-8d%s", score.score, score.scorer), (8 * Constants.TILE_SIZE) + Constants.TILE_SIZE/2, (18 - i) * 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game.fontRenderer.setColor(buttonPressed ? Color.BLUE : Color.WHITE);
|
||||||
|
game.fontRenderer.draw(game.batch, "return", 11 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,6 +69,7 @@ public class HighScoresState extends State {
|
|||||||
public boolean keyDown(int keycode) {
|
public boolean keyDown(int keycode) {
|
||||||
switch(keycode) {
|
switch(keycode) {
|
||||||
case Input.Keys.ENTER:
|
case Input.Keys.ENTER:
|
||||||
|
case Input.Keys.BACK:
|
||||||
case Input.Keys.ESCAPE:
|
case Input.Keys.ESCAPE:
|
||||||
game.setNextState(new MenuState(game));
|
game.setNextState(new MenuState(game));
|
||||||
break;
|
break;
|
||||||
@ -63,6 +77,30 @@ public class HighScoresState extends State {
|
|||||||
return super.keyDown(keycode);
|
return super.keyDown(keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
|
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||||
|
if (BUTTON.contains(coords)) {
|
||||||
|
buttonPressed = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
if (!buttonPressed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
buttonPressed = false;
|
||||||
|
|
||||||
|
Vector2 coords = game.viewport.unproject(new Vector2(screenX, screenY));
|
||||||
|
if (BUTTON.contains(coords)) {
|
||||||
|
game.setNextState(new MenuState(game));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ public class MenuState extends LevelState {
|
|||||||
public static final int NEW_GAME = 0;
|
public static final int NEW_GAME = 0;
|
||||||
public static final int HIGH_SCORES = 1;
|
public static final int HIGH_SCORES = 1;
|
||||||
|
|
||||||
private BoundingBox NEW_GAME_BOX = new BoundingBox(88, 66, 136, 84);
|
private static final BoundingBox NEW_GAME_BOX = new BoundingBox(88, 66, 136, 84);
|
||||||
private BoundingBox HIGH_SCORE_BOX = new BoundingBox(88, 42, 136, 60);
|
private static final BoundingBox HIGH_SCORE_BOX = new BoundingBox(88, 42, 136, 60);
|
||||||
|
|
||||||
private int selectedOption;
|
private int selectedOption;
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ public class MenuState extends LevelState {
|
|||||||
|
|
||||||
switch(Gdx.app.getType()) {
|
switch(Gdx.app.getType()) {
|
||||||
case Android:
|
case Android:
|
||||||
|
case iOS:
|
||||||
selectedOption = -1;
|
selectedOption = -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user