From 5645b4bcf5819659a654d60987277e838b1667ff Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 22 Jan 2020 19:42:49 +0400 Subject: [PATCH] Add visible return/save buttons to high scores pages --- android/assets/high_scores_background.png | Bin 2308 -> 2296 bytes .../me/pacman/state/HighScoreEntryState.java | 44 ++++++++++++++++-- .../com/me/pacman/state/HighScoresState.java | 38 +++++++++++++++ core/src/com/me/pacman/state/MenuState.java | 5 +- 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/android/assets/high_scores_background.png b/android/assets/high_scores_background.png index 646d514ba44b617effecebbf4f00cb4f14c03acd..82b60f1d56472e08bec63e5e7ea9f6784d18966f 100644 GIT binary patch literal 2296 zcmZ`*c~lbU7RS^eo5*x3t#N6zUQ=p5eZ5K$wda~!nJvl)nwBeJiz}k!b6iR#vX?oz zO@<3v=1Q7~$0oIdic5-!ib}Zw5+j1j;=`6xr*r0y@B9Avw%@(?cYpV0oc3_qrm;r@ z003-raklqTu9M2K0@|#cm&+G+E0-;i&OSE)0Pvq1L*;*m!FvG!5Xr^f&O0`rKi-ex zbnM#fA2*f8N^R82z3b(5>XZwRm9Z^`Psv>m=xqP z9<=r+#hG5=FWD@#$jp`r3L3hQj3#8=qG;QKjB%RIfPHrXCyOgLtKkAQ_20+o?@Zo4=26nPO}XOJ?ZgGqi3iY1?C;Q8>(o1_cRKCiAIRU z*3)PS*#A8@XR5)#JDrZ0q))Vllpu?)jj}8L@U)S(Ts_QW?M8{XmLAfyxH8;rHO);G zss|o}V|~P8_;%2Ln@F1LR2zkxpIh%l>ro0zuqKLfl`6q+7}tX@UfQ0^GyqN#uJ&}6 zLM8{gJ!Y5(W1nFDs@c=lfEt-u7mLO6ie-rqfk=cJ;H%4av7H6|pB~D$j+gm8!Z(@G z2)@V^i3CNnE7eB4l-tDLUA{`?E>)HbWA0q#s?=2{(LVnTbtD5Eb+DJ5^*+@0v#3GK zmXpMsXR&sZdn7Y~gC=tWTeldBhZ043ag`>cxt+jWTAku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com/me/pacman/state/HighScoreEntryState.java index 2f2c7f7..9995c3b 100644 --- a/core/src/com/me/pacman/state/HighScoreEntryState.java +++ b/core/src/com/me/pacman/state/HighScoreEntryState.java @@ -5,11 +5,14 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.math.Vector2; import com.me.pacman.Constants; import com.me.pacman.FontRenderer; import com.me.pacman.Score; import com.me.pacman.PacDude; +import static com.me.pacman.state.HighScoresState.BUTTON; + public class HighScoreEntryState extends State { private Texture background; @@ -21,6 +24,8 @@ public class HighScoreEntryState extends State { private boolean flash; private float elapsed; + private boolean buttonPressed; + public HighScoreEntryState(PacDude game, Score score) { super(game); this.score = score; @@ -58,6 +63,9 @@ public class HighScoreEntryState extends State { 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.setColor(buttonPressed ? Color.BLUE : Color.WHITE); + game.fontRenderer.draw(game.batch, "save", 12 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1); } @Override @@ -74,6 +82,12 @@ public class HighScoreEntryState extends State { 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 { @Override @@ -110,15 +124,39 @@ public class HighScoreEntryState extends State { flash = true; break; case Input.Keys.ENTER: - score.scorer = String.valueOf(name); - game.highScores.addScore(score); - game.setNextState(new HighScoresState(game)); + case Input.Keys.BACK: + case Input.Keys.ESCAPE: + saveScoreAndReturn(); break; } elapsed = 0f; 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; + } + } } diff --git a/core/src/com/me/pacman/state/HighScoresState.java b/core/src/com/me/pacman/state/HighScoresState.java index f1efced..79a1d10 100644 --- a/core/src/com/me/pacman/state/HighScoresState.java +++ b/core/src/com/me/pacman/state/HighScoresState.java @@ -5,15 +5,25 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.math.Vector2; import com.me.pacman.Constants; import com.me.pacman.PacDude; import com.me.pacman.Score; 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 boolean buttonPressed = false; + + public HighScoresState(PacDude game) { super(game); } @@ -40,6 +50,9 @@ public class HighScoresState extends State { 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.setColor(buttonPressed ? Color.BLUE : Color.WHITE); + game.fontRenderer.draw(game.batch, "return", 11 * Constants.TILE_SIZE, 5 * Constants.TILE_SIZE - 1); } @Override @@ -56,6 +69,7 @@ public class HighScoresState extends State { public boolean keyDown(int keycode) { switch(keycode) { case Input.Keys.ENTER: + case Input.Keys.BACK: case Input.Keys.ESCAPE: game.setNextState(new MenuState(game)); break; @@ -63,6 +77,30 @@ public class HighScoresState extends State { 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; + } + } } diff --git a/core/src/com/me/pacman/state/MenuState.java b/core/src/com/me/pacman/state/MenuState.java index 475f277..0071222 100644 --- a/core/src/com/me/pacman/state/MenuState.java +++ b/core/src/com/me/pacman/state/MenuState.java @@ -19,8 +19,8 @@ public class MenuState extends LevelState { public static final int NEW_GAME = 0; public static final int HIGH_SCORES = 1; - private 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 NEW_GAME_BOX = new BoundingBox(88, 66, 136, 84); + private static final BoundingBox HIGH_SCORE_BOX = new BoundingBox(88, 42, 136, 60); private int selectedOption; @@ -39,6 +39,7 @@ public class MenuState extends LevelState { switch(Gdx.app.getType()) { case Android: + case iOS: selectedOption = -1; break; default: