Added "Hi-Score" support
This commit is contained in:
parent
67128fad8f
commit
ceb5f6b16b
4 changed files with 42 additions and 3 deletions
BIN
gfx/hud.png
BIN
gfx/hud.png
Binary file not shown.
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 182 KiB |
|
@ -37,6 +37,8 @@
|
|||
- PCMD_UNLOCK_STAGES_WITH_DIFFICULTY:
|
||||
Unlocks one or more stages, each on a specific difficulty
|
||||
|
||||
- PCMD_HISCORE
|
||||
Sets the "Hi-Score" (highest score ever attained in one game session)
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -54,6 +56,8 @@
|
|||
|
||||
*/
|
||||
|
||||
GlobalProgress progress;
|
||||
|
||||
static uint8_t progress_magic_bytes[] = {
|
||||
0x00, 0x67, 0x74, 0x66, 0x6f, 0xe3, 0x83, 0x84
|
||||
};
|
||||
|
@ -150,6 +154,10 @@ static void progress_read(SDL_RWops *file) {
|
|||
}
|
||||
break;
|
||||
|
||||
case PCMD_HISCORE:
|
||||
progress.hiscore = SDL_ReadLE32(vfile);
|
||||
break;
|
||||
|
||||
default:
|
||||
log_warn("Unknown command %i, skipping %u bytes", cmd, cmdsize);
|
||||
while(cur++ < cmdsize)
|
||||
|
@ -276,6 +284,20 @@ static void progress_write_cmd_unlock_stages_with_difficulties(SDL_RWops *vfile,
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// PCMD_HISCORE
|
||||
//
|
||||
|
||||
static void progress_prepare_cmd_hiscore(size_t *bufsize, void **arg) {
|
||||
*bufsize += CMD_HEADER_SIZE + sizeof(uint32_t);
|
||||
}
|
||||
|
||||
static void progress_write_cmd_hiscore(SDL_RWops *vfile, void **arg) {
|
||||
SDL_WriteU8(vfile, PCMD_HISCORE);
|
||||
SDL_WriteLE16(vfile, sizeof(uint32_t));
|
||||
SDL_WriteLE32(vfile, progress.hiscore);
|
||||
}
|
||||
|
||||
static void progress_write(SDL_RWops *file) {
|
||||
size_t bufsize = 0;
|
||||
SDL_RWwrite(file, progress_magic_bytes, 1, sizeof(progress_magic_bytes));
|
||||
|
@ -283,6 +305,7 @@ static void progress_write(SDL_RWops *file) {
|
|||
cmd_writer_t cmdtable[] = {
|
||||
{progress_prepare_cmd_unlock_stages, progress_write_cmd_unlock_stages, NULL},
|
||||
{progress_prepare_cmd_unlock_stages_with_difficulties, progress_write_cmd_unlock_stages_with_difficulties, NULL},
|
||||
{progress_prepare_cmd_hiscore, progress_write_cmd_hiscore, NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
@ -338,6 +361,8 @@ static void progress_unlock_all(void) {
|
|||
#endif
|
||||
|
||||
void progress_load(void) {
|
||||
memset(&progress, 0, sizeof(GlobalProgress));
|
||||
|
||||
#ifdef PROGRESS_UNLOCK_ALL
|
||||
progress_unlock_all();
|
||||
progress_save();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
typedef enum ProgfileCommand {
|
||||
PCMD_UNLOCK_STAGES,
|
||||
PCMD_UNLOCK_STAGES_WITH_DIFFICULTY,
|
||||
PCMD_HISCORE,
|
||||
} ProgfileCommand;
|
||||
|
||||
typedef struct StageProgress {
|
||||
|
@ -32,6 +33,12 @@ typedef struct StageProgress {
|
|||
// short num_cleared;
|
||||
} StageProgress;
|
||||
|
||||
typedef struct GlobalProgress {
|
||||
uint32_t hiscore;
|
||||
} GlobalProgress;
|
||||
|
||||
extern GlobalProgress progress;
|
||||
|
||||
void progress_load(void);
|
||||
void progress_save(void);
|
||||
|
||||
|
|
13
src/stage.c
13
src/stage.c
|
@ -360,13 +360,16 @@ void draw_hud(void) {
|
|||
}
|
||||
|
||||
sprintf(buf, "%.2f", global.plr.power / 100.0);
|
||||
draw_text(AL_Center, 10, 236, buf, _fonts.standard);
|
||||
draw_text(AL_Left, -6, 236, buf, _fonts.standard);
|
||||
|
||||
sprintf(buf, "%i", global.plr.graze);
|
||||
draw_text(AL_Left, -5, 270, buf, _fonts.standard);
|
||||
draw_text(AL_Left, -6, 270, buf, _fonts.standard);
|
||||
|
||||
sprintf(buf, "%i", global.plr.points);
|
||||
draw_text(AL_Center, 13, 49, buf, _fonts.standard);
|
||||
draw_text(AL_Left, 8, 49, buf, _fonts.standard);
|
||||
|
||||
sprintf(buf, "%i", progress.hiscore);
|
||||
draw_text(AL_Left, 8, 83, buf, _fonts.standard);
|
||||
|
||||
if(global.plr.iddqd) {
|
||||
draw_text(AL_Left, -70, 475, "GOD MODE", _fonts.mainmenu);
|
||||
|
@ -748,6 +751,10 @@ void stage_loop(StageInfo *stage) {
|
|||
|
||||
stage_logic();
|
||||
|
||||
if(global.replaymode == REPLAY_RECORD && global.plr.points > progress.hiscore) {
|
||||
progress.hiscore = global.plr.points;
|
||||
}
|
||||
|
||||
if(transition_delay) {
|
||||
--transition_delay;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue