aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/entities.c3
-rw-r--r--src/map.c22
-rw-r--r--src/map.h3
3 files changed, 27 insertions, 1 deletions
diff --git a/src/entities.c b/src/entities.c
index 321af98..6b6c7a1 100644
--- a/src/entities.c
+++ b/src/entities.c
@@ -101,6 +101,9 @@ void entities_draw()
{
Rect dst = { 0, 0, 16, 16 };
+ /* in case we need to clean collected gold */
+ map_erase();
+
player_erase();
for (uint8_t i = 0; i < last; i++)
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;
}
diff --git a/src/map.h b/src/map.h
index 138abcd..9f5a06a 100644
--- a/src/map.h
+++ b/src/map.h
@@ -17,6 +17,9 @@
void map_init(const uint8_t map[]);
void map_render();
+/* for gold */
+void map_erase();
+
uint8_t map_is_blocked(uint16_t x, uint16_t y);
uint8_t map_is_deadly(uint16_t x, uint16_t y);