From 273026bf7e21865ef305af22dc8826be462117f0 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 20 Jul 2023 23:19:50 +0100 Subject: 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. --- src/map.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/map.c') 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; } -- cgit v1.2.3