From f88ab2affc7b1a4c91278444c80977b83b2556cb Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 13 Jul 2023 22:44:40 +0100 Subject: Add intro screen --- src/data.h | 3 +++ src/game.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'src') diff --git a/src/data.h b/src/data.h index 39b3da9..29377cb 100644 --- a/src/data.h +++ b/src/data.h @@ -10,6 +10,9 @@ extern const uint8_t binary_tiles_start[]; extern const uint8_t binary_font_start[]; extern const uint8_t binary_title_start[]; +/* intro map */ +extern const uint8_t binary_intro_start[]; + /* maps */ extern const uint8_t binary_stage01_start[]; extern const uint8_t binary_stage02_start[]; diff --git a/src/game.c b/src/game.c index 85fb050..7fe6d78 100644 --- a/src/game.c +++ b/src/game.c @@ -110,6 +110,67 @@ static void hud_render() hud = HUD_CLEAN; } +#define WALK_DELAY 8 +#define WALK_CYCLE_FRAMES 4 + +static const Rect intro_frames[WALK_CYCLE_FRAMES] = +{ + /* walk cycle */ + { 0, 0, 144, 144 }, + { 16, 0, 144, 144 }, + { 0, 0, 144, 144 }, + { 32, 0, 144, 144 }, +}; + +static void run_intro() +{ + /* for the HUD */ + pickaxe = 0; + time = GAME_TIME_MAX; + hud = HUD_ALL; + + blit_target(TARGET_BUFFER); + blit_erase(0); + + map_init(binary_intro_start); + + map_render(); + hud_render(); + put_text(88, 65, "GET ALL THAT GOLD!", 1); + + wait_vsync(); + blit_copy_all(); + + Rect dst = { 80, 88 + MAP_OFFS_Y, 16, 16 }; + uint8_t frame = 0, delay = 0; + + wait_frames(32); + + blit_target(TARGET_SCREEN); + while (dst.x < 224) + { + wait_vsync(); + blit_copy16(&dst); + dst.x++; + if (map_update_gold(dst.x + 8, dst.y + 15 - MAP_OFFS_Y)) + sound_play_efx(EFX_GOLD); + blitrc(binary_sprites_start, &intro_frames[frame], &dst); + + if (delay++ == WALK_DELAY) + { + delay = 0; + frame++; + if (frame == WALK_CYCLE_FRAMES) + frame = 0; + } + } + + wait_vsync(); + blit_copy16(&dst); + + wait_frames(64); +} + static void run_gameover() { wait_vsync(); @@ -167,6 +228,8 @@ void run_game() score = 0; stage = 0; + run_intro(); + next_stage: pause = 0; gameover = 0; -- cgit v1.2.3