aboutsummaryrefslogtreecommitdiff
path: root/src/map.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-20 23:19:50 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-20 23:24:56 +0100
commit273026bf7e21865ef305af22dc8826be462117f0 (patch)
tree129ec9d103d986dd1aea23395f1dfcf99b3f186d /src/map.c
parentf00ca8c1a2ae1c59854e60b13d3f529ab9e685c5 (diff)
downloadgold-mine-run-273026bf7e21865ef305af22dc8826be462117f0.tar.gz
gold-mine-run-273026bf7e21865ef305af22dc8826be462117f0.zip
Erase collected gold
Although the erase code of the player is likely to clean the gold after being picked up, there could be some left overs in some corner cases, so we let the map erase the gold to ensure it is 100% clean.
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/map.c b/src/map.c
index 4aafdca..26c91ac 100644
--- a/src/map.c
+++ b/src/map.c
@@ -18,9 +18,11 @@
#include "map.h"
/* current map; set via map_init */
-static uint8_t cmap[MAP_W * MAP_H];
+static uint8_t cmap[MAP_W * MAP_H];
static uint8_t gold[MAP_W * MAP_H];
static uint8_t total_gold;
+static uint8_t erase;
+static uint16_t ex, ey;
static void (* const init[])(Entity *) =
{
@@ -84,6 +86,8 @@ void map_init(const uint8_t map[])
init[*ent - 1](e);
}
+
+ erase = 0;
}
void map_render()
@@ -126,6 +130,17 @@ uint8_t map_is_deadly(uint16_t x, uint16_t y)
return cmap[(x / MAP_TILE_W) + (y / MAP_TILE_H) * MAP_W] >= MAP_FIRST_DEADLY;
}
+void map_erase()
+{
+ if (!erase)
+ return;
+
+ Rect dst = { ex, ey, 8, 8 };
+ blit_copy(&dst);
+
+ erase = 0;
+}
+
uint8_t map_update_gold(uint16_t x, uint16_t y)
{
Rect src = { 0, 0, 160, 48 };
@@ -151,6 +166,11 @@ uint8_t map_update_gold(uint16_t x, uint16_t y)
blitrc(binary_tiles_start, &src, &dst);
blit_target(TARGET_SCREEN);
+ /* will be used by map_erase */
+ ex = dst.x;
+ ey = dst.y;
+ erase = 1;
+
total_gold--;
return 1;
}