aboutsummaryrefslogtreecommitdiff
path: root/src/map.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-11 23:11:21 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-11 23:11:21 +0100
commit4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed (patch)
tree70ba7352bb0e9674923ce839578b33253059660c /src/map.c
parent4a82c31f67d74be952a9e60506cde7ba31c15214 (diff)
downloadgold-mine-run-4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed.tar.gz
gold-mine-run-4c4ffc1b84ada5dc47f9d36e9154564b68ff7fed.zip
Add gol/silver keys and door logic
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c63
1 files changed, 60 insertions, 3 deletions
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;