From 5efea24f028e595433caa8707c3b25c98d1aedbf Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 4 Jul 2023 23:20:45 +0100 Subject: Stage complete sequence --- TODO.md | 1 - src/game.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/TODO.md b/TODO.md index acf2e2c..a6360d2 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ - pick ups - key / doors -- end of stage - enemies - free - tracker diff --git a/src/game.c b/src/game.c index 9d126d1..101a053 100644 --- a/src/game.c +++ b/src/game.c @@ -29,6 +29,7 @@ #define HUD_ALL 255 #define GAMEOVER_DELAY 96 +#define STAGECLEAR_DELAY 96 static uint32_t hiscore = 15000; @@ -41,6 +42,7 @@ static uint32_t score; static uint8_t stage; static uint8_t time; static uint8_t pickaxe; +static uint8_t stageclear; static uint8_t gameover; static uint8_t pause; static Entity *tmonster; @@ -87,8 +89,8 @@ static void hud_render() if (hud & HUD_TIME) { sprintf(b, "%02d", time); - put_text(172, 4, b, time > 10 ? 1 : 15); - if (!gameover && time <= 10) + put_text(172, 4, b, time > 10 || stageclear ? 1 : 15); + if (!gameover && !stageclear && time <= 10) sound_queue_efx(EFX_TIME); } @@ -118,20 +120,58 @@ static void run_gameover() wait_frames(255); } -void run_game() +static void run_stageclear() { - pause = 0; - gameover = 0; + put_text(116, 100, "STAGE CLEAR", 1); + + wait_vsync(); + blit_update(); + + /* wait some time */ + wait_frames(96); + + while (time--) + { + add_score(25); + hud |= HUD_TIME; + sound_queue_efx(EFX_GOLD); + hud_render(); + + wait_frames(4); + blit_update(); + sound_play_queue(); + } + + /* wait some time */ + wait_frames(64); + + blit_erase(0); + /* restore the HUD after erasing the screen */ + hud = HUD_ALL; + hud_render(); + wait_vsync(); + blit_update(); + wait_frames(32); +} + +void run_game() +{ lives = GAME_LIVES_START; score = 0; stage = 0; + +next_stage: + pause = 0; + gameover = 0; + stageclear = 0; + pickaxe = 0; time = GAME_TIME_MAX; - tmonster = NULL; - hud = HUD_ALL; + tmonster = NULL; + blit_erase(0); map_init(binary_stage_start); @@ -189,34 +229,51 @@ void run_game() player_erase(); entities_erase(); - player_update(); - entities_update(); - - /* time monster */ - if (!time && !tmonster) + if (map_is_complete()) { - tmonster = entities_new(); - if (tmonster) - tmonster_init(tmonster); + if (!stageclear) + { + timer_stop(); + tmonster = NULL; + entities_warp_out_all(); + sound_queue_efx(EFX_WARP); + + stageclear = STAGECLEAR_DELAY; + } + else + { + stageclear--; + if (stageclear == 1) + { + run_stageclear(); + goto next_stage; + } + } } - if (time && tmonster) + else { - tmonster->used = 0; - tmonster = NULL; - } + player_update(); - if (map_is_complete()) - { - tmonster = NULL; - timer_stop(); - entities_warp_out_all(); + /* time monster */ + if (!time && !tmonster) + { + tmonster = entities_new(); + if (tmonster) + tmonster_init(tmonster); + } + if (time && tmonster) + { + tmonster->used = 0; + tmonster = NULL; + } } + entities_update(); + entities_draw(); player_draw(); wait_vsync(); - blit_update(); sound_play_queue(); -- cgit v1.2.3