diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-11 23:11:21 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-11 23:11:21 +0100 |
commit | 4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed (patch) | |
tree | 70ba7352bb0e9674923ce839578b33253059660c /src/pickup.c | |
parent | 4a82c31f67d74be952a9e60506cde7ba31c15214 (diff) | |
download | gold-mine-run-4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed.tar.gz gold-mine-run-4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed.zip |
Add gol/silver keys and door logic
Diffstat (limited to 'src/pickup.c')
-rw-r--r-- | src/pickup.c | 51 |
1 files changed, 45 insertions, 6 deletions
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); } } |