From 3b751d86e5250df530cb694c6bbe44829006c013 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 16 Jul 2023 21:53:30 +0100 Subject: Extra life at 10,000 Also with special sound. --- data/oneup_efx.wav | Bin 0 -> 130378 bytes src/data.h | 2 ++ src/game.c | 17 +++++++++++++++++ src/sound.c | 3 ++- src/sound.h | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 data/oneup_efx.wav diff --git a/data/oneup_efx.wav b/data/oneup_efx.wav new file mode 100644 index 0000000..365c542 Binary files /dev/null and b/data/oneup_efx.wav differ diff --git a/src/data.h b/src/data.h index 0006a4a..255ec35 100644 --- a/src/data.h +++ b/src/data.h @@ -36,6 +36,7 @@ extern const uint8_t binary_time_efx_start[]; extern const uint8_t binary_gold_efx_start[]; extern const uint8_t binary_pickup_efx_start[]; extern const uint8_t binary_warp_efx_start[]; +extern const uint8_t binary_oneup_efx_start[]; extern const uint8_t binary_hit_efx_size; extern const uint8_t binary_death_efx_size; @@ -44,5 +45,6 @@ extern const uint8_t binary_time_efx_size; extern const uint8_t binary_gold_efx_size; extern const uint8_t binary_pickup_efx_size; extern const uint8_t binary_warp_efx_size; +extern const uint8_t binary_oneup_efx_size; #endif /* _DATA_H */ diff --git a/src/game.c b/src/game.c index 609299f..c18b9ad 100644 --- a/src/game.c +++ b/src/game.c @@ -21,6 +21,8 @@ #define GAME_TIME_MAX 60 #define GAME_MAX_PICKAXE 3 +#define GAME_EXTRA_LIFE ((uint16_t)10000) + #define HUD_CLEAN 0 #define HUD_LIVES 1 #define HUD_SCORE 2 @@ -40,6 +42,7 @@ static volatile uint8_t clock_updated; /* game variables */ static uint8_t lives; static uint32_t score; +static uint16_t extra_life; static uint8_t stage; static uint8_t time; static uint8_t pickaxe; @@ -231,6 +234,7 @@ void run_game() { lives = GAME_LIVES_START; score = 0; + extra_life = 0; stage = START_STAGE; run_intro(); @@ -380,6 +384,19 @@ next_stage: void add_score(uint8_t v) { score += v; + extra_life += v; + + if (extra_life >= GAME_EXTRA_LIFE) + { + extra_life -= GAME_EXTRA_LIFE; + if (lives < 9) + { + sound_play_efx(EFX_ONEUP); + lives++; + hud |= HUD_LIVES; + } + } + hud |= HUD_SCORE; } diff --git a/src/sound.c b/src/sound.c index c9e3b1c..aeeeeb8 100644 --- a/src/sound.c +++ b/src/sound.c @@ -12,7 +12,7 @@ typedef struct size_t len; } Efx; -#define EFX_CNT 7 +#define EFX_CNT 8 static Efx efx[EFX_CNT] = { @@ -21,6 +21,7 @@ static Efx efx[EFX_CNT] = { NULL, (const char *)binary_warp_efx_start, (size_t)&binary_warp_efx_size}, { NULL, (const char *)binary_pickup_efx_start, (size_t)&binary_pickup_efx_size}, { NULL, (const char *)binary_time_efx_start, (size_t)&binary_time_efx_size}, + { NULL, (const char *)binary_oneup_efx_start, (size_t)&binary_oneup_efx_size}, { NULL, (const char *)binary_hit_efx_start, (size_t)&binary_hit_efx_size}, { NULL, (const char *)binary_death_efx_start, (size_t)&binary_death_efx_size}, }; diff --git a/src/sound.h b/src/sound.h index d8b14ac..5f96d29 100644 --- a/src/sound.h +++ b/src/sound.h @@ -7,6 +7,7 @@ enum { EFX_WARP, EFX_PICKUP, EFX_TIME, + EFX_ONEUP, EFX_HIT, EFX_DEATH, }; -- cgit v1.2.3