Save on pause, don't save time mode, ignore *.sav files
This commit is contained in:
parent
f954766d99
commit
c02c00ee64
5 changed files with 27 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
## Klooni save data
|
||||||
|
*.sav
|
||||||
|
|
||||||
## Java
|
## Java
|
||||||
|
|
||||||
*.class
|
*.class
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB |
|
@ -44,7 +44,6 @@ public class Klooni extends Game {
|
||||||
skin.add("play_saved_texture", new Texture(Gdx.files.internal("ui/play_saved.png")));
|
skin.add("play_saved_texture", new Texture(Gdx.files.internal("ui/play_saved.png")));
|
||||||
skin.add("star_texture", new Texture(Gdx.files.internal("ui/star.png")));
|
skin.add("star_texture", new Texture(Gdx.files.internal("ui/star.png")));
|
||||||
skin.add("stopwatch_texture", new Texture(Gdx.files.internal("ui/stopwatch.png")));
|
skin.add("stopwatch_texture", new Texture(Gdx.files.internal("ui/stopwatch.png")));
|
||||||
skin.add("stopwatch_saved_texture", new Texture(Gdx.files.internal("ui/stopwatch_saved.png")));
|
|
||||||
skin.add("palette_texture", new Texture(Gdx.files.internal("ui/palette.png")));
|
skin.add("palette_texture", new Texture(Gdx.files.internal("ui/palette.png")));
|
||||||
skin.add("home_texture", new Texture(Gdx.files.internal("ui/home.png")));
|
skin.add("home_texture", new Texture(Gdx.files.internal("ui/home.png")));
|
||||||
skin.add("replay_texture", new Texture(Gdx.files.internal("ui/replay.png")));
|
skin.add("replay_texture", new Texture(Gdx.files.internal("ui/replay.png")));
|
||||||
|
|
|
@ -88,13 +88,14 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
|
|
||||||
gameOverSound = Gdx.audio.newSound(Gdx.files.internal("sound/game_over.mp3"));
|
gameOverSound = Gdx.audio.newSound(Gdx.files.internal("sound/game_over.mp3"));
|
||||||
|
|
||||||
if (loadSave) {
|
if (gameMode == GAME_MODE_SCORE) {
|
||||||
// The user might have a previous game. If this is the case, load it
|
if (loadSave) {
|
||||||
tryLoad();
|
// The user might have a previous game. If this is the case, load it
|
||||||
}
|
tryLoad();
|
||||||
else {
|
} else {
|
||||||
// Ensure that there is no old save, we don't want to load it, thus delete it
|
// Ensure that there is no old save, we don't want to load it, thus delete it
|
||||||
deleteSave();
|
deleteSave();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +122,8 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
gameOverSound.play();
|
gameOverSound.play();
|
||||||
|
|
||||||
// The user should not be able to return to the game if its game over
|
// The user should not be able to return to the game if its game over
|
||||||
deleteSave();
|
if (gameMode == GAME_MODE_SCORE)
|
||||||
|
deleteSave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +139,15 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
Gdx.input.setInputProcessor(this);
|
Gdx.input.setInputProcessor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save the state, the user might leave the game in any of the following 2 methods
|
||||||
private void showPauseMenu() {
|
private void showPauseMenu() {
|
||||||
pauseMenu.show(false);
|
pauseMenu.show(false);
|
||||||
save(); // Save the state, the user might leave the game
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -214,14 +222,11 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) { }
|
public void resize(int width, int height) { }
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() { }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resume() { }
|
public void resume() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hide() { }
|
public void hide() { /* Hide can only be called if the menu was shown. Place logic there. */ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode) {
|
public boolean keyDown(int keycode) {
|
||||||
|
@ -253,8 +258,10 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
//region Saving and loading
|
//region Saving and loading
|
||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
// Only save if the game is not over
|
// Only save if the game is not over and the game mode is not the time mode. It
|
||||||
if (gameOverDone)
|
// makes no sense to save the time game mode since it's supposed to be something quick.
|
||||||
|
// Don't save either if the score is 0, which means the player did nothing.
|
||||||
|
if (gameOverDone || gameMode != GAME_MODE_SCORE || scorer.getCurrentScore() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
||||||
|
@ -266,7 +273,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deleteSave() {
|
private void deleteSave() {
|
||||||
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
||||||
if (handle.exists())
|
if (handle.exists())
|
||||||
handle.delete();
|
handle.delete();
|
||||||
|
@ -277,7 +284,6 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tryLoad() {
|
private boolean tryLoad() {
|
||||||
// Load will fail if the game modes differ, but that's okay
|
|
||||||
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
final FileHandle handle = Gdx.files.local(SAVE_DAT_FILENAME);
|
||||||
if (handle.exists()) {
|
if (handle.exists()) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -66,9 +66,7 @@ public class MainMenuScreen extends InputListener implements Screen {
|
||||||
table.add(starButton).space(16);
|
table.add(starButton).space(16);
|
||||||
|
|
||||||
// Time mode
|
// Time mode
|
||||||
// TODO Would be nice if it actually showed the saved texture iff that's the saved game mode
|
final SoftButton statsButton = new SoftButton(2, "stopwatch_texture");
|
||||||
final SoftButton statsButton = new SoftButton(
|
|
||||||
2, GameScreen.hasSavedData() ? "stopwatch_saved_texture" : "stopwatch_texture");
|
|
||||||
statsButton.addListener(new ChangeListener() {
|
statsButton.addListener(new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ChangeEvent event, Actor actor) {
|
public void changed(ChangeEvent event, Actor actor) {
|
||||||
|
|
Loading…
Reference in a new issue