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/entities.c | 3 +++ src/map.c | 22 +++++++++++++++++++++- src/map.h | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3