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/map.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'src/map.c') diff --git a/src/map.c b/src/map.c index 5599ae9..4aafdca 100644 --- a/src/map.c +++ b/src/map.c @@ -7,6 +7,7 @@ #include "data.h" #include "entities.h" +#include "effect.h" #include "player.h" #include "snake.h" #include "bat.h" @@ -17,7 +18,7 @@ #include "map.h" /* current map; set via map_init */ -static const uint8_t *cmap; +static uint8_t cmap[MAP_W * MAP_H]; static uint8_t gold[MAP_W * MAP_H]; static uint8_t total_gold; @@ -30,14 +31,17 @@ static void (* const init[])(Entity *) = pickup_time_init, pickup_bonus_init, pickup_pickaxe_init, + pickup_goldkey_init, + pickup_silverkey_init, }; void map_init(const uint8_t map[]) { - cmap = map; + /* make a copy of the map data in RAM */ + memcpy(cmap, map, MAP_W * MAP_H); /* make a copy of the gold data in RAM */ - memcpy(gold, cmap + MAP_W * MAP_H, MAP_W * MAP_H); + memcpy(gold, map + MAP_W * MAP_H, MAP_W * MAP_H); /* count how many pieces of gold on this map */ total_gold = 0; @@ -154,6 +158,59 @@ uint8_t map_update_gold(uint16_t x, uint16_t y) return 0; } +static void map_open_key(uint8_t top, uint8_t bottom) +{ + Rect src = { 0, 0, 160, 48 }; + Rect dst = { 0, 0, 16, 8 }; + + blit_target(TARGET_BUFFER); + + for (uint8_t y = 0; y < MAP_H; y++) + for (uint8_t x = 0; x < MAP_W; x++) + { + uint8_t t = cmap[x + y * MAP_W]; + + if (t == top || t == bottom) + { + /* not solid */ + cmap[x + y * MAP_W] = 0; + cmap[x + 1 + y * MAP_W] = 0; + + dst.x = x * MAP_TILE_W; + dst.y = y * MAP_TILE_H + MAP_OFFS_Y; + + /* top */ + if (t == top) + { + src.x = 64; + src.y = 0; + + effect_out_new(x * MAP_TILE_W, y * MAP_TILE_H); + } + else + { + /* bottom */ + src.x = 32; + src.y = 8; + } + blitrc(binary_tiles_start, &src, &dst); + continue; + } + } + + blit_target(TARGET_SCREEN); +} + +void map_open_goldkey() +{ + map_open_key(45, 65); +} + +void map_open_silverkey() +{ + map_open_key(47, 67); +} + uint8_t map_is_complete() { return total_gold == 0; -- cgit v1.2.3