Fix saving

merge-requests/2/head
Miloslav Číž 2020-11-10 14:16:14 +01:00
parent 9ba6a5b8ea
commit 69efe67ac1
2 changed files with 15 additions and 15 deletions

26
game.h
View File

@ -390,15 +390,15 @@ struct
The save contains game settings, game progress and a
saved position. The format is as follows:
0 4b highest level that has been reached
0 4b level number of the saved position (15: no save)
1 8b game settings (SFG_game.settings)
2 8b health at saved position
3 8b bullet ammo at saved position
4 8b rocket ammo at saved position
5 8b plasma ammo at saved position
6 32b little endian total play time, in 10ths of sec
10 16b little endian total enemies killed from start */
0 4b (less signif.) highest level that has been reached
0 4b (more signif.) level number of the saved position (15: no save)
1 8b game settings (SFG_game.settings)
2 8b health at saved position
3 8b bullet ammo at saved position
4 8b rocket ammo at saved position
5 8b plasma ammo at saved position
6 32b little endian total play time, in 10ths of sec
10 16b little endian total enemies killed from start */
uint8_t continues; ///< Whether the game continues or was exited.
} SFG_game;
@ -687,9 +687,6 @@ void SFG_levelEnds()
SFG_game.save[11] += SFG_currentLevel.monstersDead / 256;
}
SFG_game.save[0] =
(SFG_game.save[0] & 0x0f) | ((SFG_currentLevel.levelNumber + 1) << 4);
SFG_game.save[2] = SFG_player.health;
SFG_game.save[3] = SFG_player.ammo[0];
SFG_game.save[4] = SFG_player.ammo[1];
@ -1711,7 +1708,7 @@ void SFG_init()
for (uint16_t i = 0; i < SFG_SAVE_SIZE; ++i)
SFG_game.save[i] = 0;
SFG_game.save[0] = 0;
SFG_game.save[0] = 0xf0;
SFG_game.save[1] = SFG_game.settings;
SFG_gameLoad(); // attempt to load settings
@ -3924,6 +3921,9 @@ void SFG_gameStep()
if (SFG_keyIsDown(SFG_KEY_RIGHT) && SFG_game.saved != SFG_CANT_SAVE)
{
// save the current position
SFG_game.save[0] =
(SFG_game.save[0] & 0x0f) | (SFG_currentLevel.levelNumber << 4);
SFG_gameSave();
SFG_game.saved = 1;
}

View File

@ -25,10 +25,10 @@
#endif
// #define SFG_START_LEVEL 1
// #define SFG_IMMORTAL 1
#define SFG_IMMORTAL 1
#define SFG_UNLOCK_DOOR 1
// #define SFG_REVEAL_MAP 1
#define SFG_INFINITE_AMMO 1
// #define SFG_INFINITE_AMMO 1
// #define SFG_TIME_MULTIPLIER 512
// #define SFG_CPU_LOAD(percent) printf("CPU load: %d%\n",percent);