Fix money not being saved on death screen

This commit is contained in:
Lonami Exo 2017-04-10 10:04:49 +02:00
parent 13d837ad4b
commit 3c98079fc1

View file

@ -125,6 +125,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
if (!gameOverDone) { if (!gameOverDone) {
gameOverDone = true; gameOverDone = true;
saveMoney();
holder.enabled = false; holder.enabled = false;
pauseMenu.showGameOver(gameOverReason); pauseMenu.showGameOver(gameOverReason);
if (Klooni.soundsEnabled()) if (Klooni.soundsEnabled())
@ -150,13 +151,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
// Save the state, the user might leave the game in any of the following 2 methods // Save the state, the user might leave the game in any of the following 2 methods
private void showPauseMenu() { private void showPauseMenu() {
// Calculate new money since the previous saving saveMoney();
int nowScore = scorer.getCurrentScore();
int newMoneyScore = nowScore - savedMoneyScore;
savedMoneyScore = nowScore;
Klooni.addMoneyFromScore(newMoneyScore);
// Show the pause menu
pauseMenu.show(); pauseMenu.show();
save(); save();
} }
@ -275,6 +270,14 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
//region Saving and loading //region Saving and loading
private void saveMoney() {
// Calculate new money since the previous saving
int nowScore = scorer.getCurrentScore();
int newMoneyScore = nowScore - savedMoneyScore;
savedMoneyScore = nowScore;
Klooni.addMoneyFromScore(newMoneyScore);
}
private void save() { private void save() {
// Only save if the game is not over and the game mode is not the time mode. It // Only save if the game is not over and the game mode is not the time mode. It
// makes no sense to save the time game mode since it's supposed to be something quick. // makes no sense to save the time game mode since it's supposed to be something quick.