diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-20 23:19:50 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-20 23:24:56 +0100 |
commit | 273026bf7e21865ef305af22dc8826be462117f0 (patch) | |
tree | 129ec9d103d986dd1aea23395f1dfcf99b3f186d /src/map.c | |
parent | f00ca8c1a2ae1c59854e60b13d3f529ab9e685c5 (diff) | |
download | gold-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.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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; } |