From 4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Tue, 11 Jul 2023 23:11:21 +0100 Subject: Add gol/silver keys and door logic --- src/pickup.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'src/pickup.c') diff --git a/src/pickup.c b/src/pickup.c index afc5ef2..fe7d15e 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -4,6 +4,7 @@ #include "vga.h" #include "sound.h" #include "entities.h" +#include "map.h" #include "game.h" #include "player.h" @@ -21,8 +22,8 @@ typedef enum PICKUP_TIME = 0, PICKUP_BONUS, PICKUP_PICKAXE, - PICKUP_GOLD_KEY, - PICKUP_SILVER_KEY, + PICKUP_GOLDKEY, + PICKUP_SILVERKEY, } PickupType; static const Rect frames_in[2 * 4] = @@ -48,10 +49,10 @@ static const Rect frames[2 * 4] = { 64, 16, 144, 144 }, /* gold key */ - { 0, 0, 144, 144 }, + { 32, 16, 144, 144 }, /* siver key */ - { 0, 0, 144, 144 }, + { 48, 16, 144, 144 }, /* not used */ { 0, 0, 144, 144 }, @@ -134,6 +135,24 @@ void pickup_pickaxe_init(Entity *e) e->update = pickup_wait_update; } +void pickup_goldkey_init(Entity *e) +{ + e->used = USED_BG; + e->frames = (const Rect *)frames_in; + e->flags = PICKUP_GOLDKEY; + e->counter = 2 + (rand() % MAX_TTL); + e->update = pickup_wait_update; +} + +void pickup_silverkey_init(Entity *e) +{ + e->used = USED_BG; + e->frames = (const Rect *)frames_in; + e->flags = PICKUP_SILVERKEY; + e->counter = 2 + (rand() % MAX_TTL); + e->update = pickup_wait_update; +} + void pickup_wait_update(Entity *e) { if (e->counter-- == 0) @@ -165,6 +184,14 @@ void pickup_in_update(Entity *e) e->frames = (const Rect *)frames; e->frame = 1; break; + case PICKUP_GOLDKEY: + e->frames = (const Rect *)frames; + e->frame = 2; + break; + case PICKUP_SILVERKEY: + e->frames = (const Rect *)frames; + e->frame = 3; + break; } e->counter = 0; e->update = pickup_update; @@ -174,7 +201,9 @@ void pickup_in_update(Entity *e) void pickup_update(Entity *e) { - if (e->counter++ == MAX_TTL) + /* the keys NEVER disappear */ + if (e->flags != PICKUP_GOLDKEY && e->flags != PICKUP_SILVERKEY + && e->counter++ == MAX_TTL) { effect_out_init(e); sound_play_efx(EFX_WARP); @@ -202,15 +231,25 @@ void pickup_update(Entity *e) { case PICKUP_TIME: reset_time(); + sound_play_efx(EFX_PICKUP); break; case PICKUP_BONUS: add_score(250); + sound_play_efx(EFX_PICKUP); break; case PICKUP_PICKAXE: add_pickaxe(); + sound_play_efx(EFX_PICKUP); + break; + case PICKUP_GOLDKEY: + map_open_goldkey(); + sound_play_efx(EFX_WARP); + break; + case PICKUP_SILVERKEY: + map_open_silverkey(); + sound_play_efx(EFX_WARP); break; } e->used = USED_FREE; - sound_play_efx(EFX_PICKUP); } } -- cgit v1.2.3