Revision | a4aa851902309bf1de4c959b32e6674abdcece85 (tree) |
---|---|
Time | 2022-01-10 00:43:40 |
Author | sebastian_bugiu |
Commiter | sebastian_bugiu |
Added save/resume game.
@@ -12,12 +12,9 @@ | ||
12 | 12 | import com.badlogic.gdx.utils.ScreenUtils; |
13 | 13 | import com.badlogic.gdx.utils.viewport.ScreenViewport; |
14 | 14 | import com.headwayent.spacerocket.old.DifficultySelection; |
15 | -import com.headwayent.spacerocket.old.ExtendedCanvas; | |
16 | 15 | import com.headwayent.spacerocket.old.Status; |
17 | 16 | |
18 | -import java.util.ArrayList; | |
19 | 17 | import java.util.Comparator; |
20 | -import java.util.HashMap; | |
21 | 18 | import java.util.TreeMap; |
22 | 19 | |
23 | 20 | public class HighScoreActivity extends ScreenAdapter { |
@@ -139,7 +136,7 @@ | ||
139 | 136 | private void saveScore(String userName) { |
140 | 137 | SpaceRocket gameEngine = SpaceRocket.getGame(); |
141 | 138 | if (gameEngine.getGameMode() == SpaceRocket.GameMode.SP) { |
142 | - gameEngine.SaveGame(userName); | |
139 | + gameEngine.saveGame(userName); | |
143 | 140 | } |
144 | 141 | Status status = gameEngine.getCanvas().getStatus(); |
145 | 142 | String msg = "Congratulations! You have reached a new " + |
@@ -36,6 +36,7 @@ | ||
36 | 36 | Skin skin = new Skin(Gdx.files.internal("uiskin.json")); |
37 | 37 | |
38 | 38 | //create buttons |
39 | + TextButton resumeGame = new TextButton("Resume Game", skin); | |
39 | 40 | TextButton newGame = new TextButton("New Game", skin); |
40 | 41 | TextButton preferences = new TextButton("Preferences", skin); |
41 | 42 | TextButton highScore = new TextButton("High Score", skin); |
@@ -44,6 +45,10 @@ | ||
44 | 45 | TextButton exit = new TextButton("Exit", skin); |
45 | 46 | |
46 | 47 | //add buttons to table |
48 | + if (SpaceRocket.getGame().isSessionResumeAvailable()) { | |
49 | + table.add(resumeGame).fillX().uniformX(); | |
50 | + table.row().pad(10, 0, 0, 0); | |
51 | + } | |
47 | 52 | table.add(newGame).fillX().uniformX(); |
48 | 53 | table.row().pad(10, 0, 0, 0); |
49 | 54 | table.add(preferences).fillX().uniformX(); |
@@ -64,6 +69,14 @@ | ||
64 | 69 | } |
65 | 70 | }); |
66 | 71 | |
72 | + resumeGame.addListener(new ChangeListener() { | |
73 | + @Override | |
74 | + public void changed(ChangeEvent event, Actor actor) { | |
75 | + SpaceRocket.getGame().changeScreen(SpaceRocket.Screen.IN_GAME); | |
76 | + SpaceRocket.getGame().resumeSession(); | |
77 | + } | |
78 | + }); | |
79 | + | |
67 | 80 | newGame.addListener(new ChangeListener() { |
68 | 81 | @Override |
69 | 82 | public void changed(ChangeEvent event, Actor actor) { |
@@ -96,6 +96,7 @@ | ||
96 | 96 | @Override |
97 | 97 | public void dispose () { |
98 | 98 | super.dispose(); |
99 | + saveSession(); | |
99 | 100 | batch.dispose(); |
100 | 101 | mainTextureAtlas.dispose(); |
101 | 102 | } |
@@ -216,7 +217,11 @@ | ||
216 | 217 | save.writeBytes(b, false); |
217 | 218 | } |
218 | 219 | |
219 | - private void resumeSession() { | |
220 | + public boolean isSessionResumeAvailable() { | |
221 | + return Gdx.files.local("save").exists(); | |
222 | + } | |
223 | + | |
224 | + public void resumeSession() { | |
220 | 225 | FileHandle save = Gdx.files.local("save"); |
221 | 226 | |
222 | 227 | canvas.getGraphicsManager().playSingle(); |
@@ -244,10 +249,11 @@ | ||
244 | 249 | xPos = Math.round(xPosF * ExtendedCanvas.getScreenWidth()); |
245 | 250 | yPos = Math.round(yPosF * ExtendedCanvas.getScreenHeight()); |
246 | 251 | canvas.load(xPos, yPos, score, lives, currentBoss, bossHealth); |
252 | + save.delete(); | |
247 | 253 | } |
248 | 254 | } |
249 | 255 | |
250 | - public void SaveGame(String userName) { | |
256 | + public void saveGame(String userName) { | |
251 | 257 | if (userName == null || "".equals(userName)) { |
252 | 258 | return; |
253 | 259 | } |
@@ -2,5 +2,5 @@ | ||
2 | 2 | app.id=com.headwayent.spacerocket |
3 | 3 | app.mainclass=com.headwayent.spacerocket.IOSLauncher |
4 | 4 | app.executable=IOSLauncher |
5 | -app.build=5 | |
5 | +app.build=6 | |
6 | 6 | app.name=Hotshot 2D |