aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-20 22:31:57 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-20 22:31:57 +0100
commitd489b6ef92ae9f61bbceb5f594026a51e71538f2 (patch)
treef0bb53c68f5f8bd6fc4e3df97a5016a8e58224cf
parent8ad4c1aa98144a1799f340a44c80a0e461ced683 (diff)
downloadgold-mine-run-d489b6ef92ae9f61bbceb5f594026a51e71538f2.tar.gz
gold-mine-run-d489b6ef92ae9f61bbceb5f594026a51e71538f2.zip
Add gold support
- added gold layer to the map - the player can collect gold - updates the score - TODO: end of stage
-rw-r--r--TODO.md3
-rw-r--r--data/stage.json14
-rw-r--r--data/tiles.pngbin7976 -> 8260 bytes
-rw-r--r--src/game.c8
-rw-r--r--src/game.h1
-rw-r--r--src/map.c66
-rw-r--r--src/map.h3
-rw-r--r--src/player.c4
-rwxr-xr-xtools/map.py5
9 files changed, 100 insertions, 4 deletions
diff --git a/TODO.md b/TODO.md
index 90387a4..ebd0632 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,7 +2,8 @@
- entity system
- free/used lists
- - player
+- player
+ - "coyote time"
- map
- entities
- pick ups
diff --git a/data/stage.json b/data/stage.json
index fc5709b..262d5cb 100644
--- a/data/stage.json
+++ b/data/stage.json
@@ -13,8 +13,20 @@
"width":40,
"x":0,
"y":0
+ },
+ {
+ "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ "height":23,
+ "id":2,
+ "name":"Gold",
+ "opacity":1,
+ "type":"tilelayer",
+ "visible":true,
+ "width":40,
+ "x":0,
+ "y":0
}],
- "nextlayerid":2,
+ "nextlayerid":3,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
diff --git a/data/tiles.png b/data/tiles.png
index 80d8d0c..3bb18c7 100644
--- a/data/tiles.png
+++ b/data/tiles.png
Binary files differ
diff --git a/src/game.c b/src/game.c
index b39b0ca..b80090a 100644
--- a/src/game.c
+++ b/src/game.c
@@ -24,7 +24,7 @@ static uint8_t stage;
static uint8_t gold;
static uint8_t time;
-void hud_render()
+static void hud_render()
{
char b[32];
@@ -106,3 +106,9 @@ void run_game()
blit_update();
}
}
+
+void add_score(uint8_t v)
+{
+ score += v;
+ hud |= HUD_SCORE;
+}
diff --git a/src/game.h b/src/game.h
index ff90121..b47004c 100644
--- a/src/game.h
+++ b/src/game.h
@@ -13,5 +13,6 @@
#define HUD_ALL 255
void run_game();
+void add_score(uint8_t v);
#endif /* _GAME_H */
diff --git a/src/map.c b/src/map.c
index 87a0b3b..9908384 100644
--- a/src/map.c
+++ b/src/map.c
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include <string.h>
#include "vga.h"
#include "data.h"
@@ -7,10 +8,22 @@
/* current map; set via map_init */
static const uint8_t *cmap;
+static uint8_t gold[MAP_W * MAP_H];
+static uint8_t total_gold;
void map_init(const uint8_t map[])
{
cmap = map;
+
+ /* make a copy of the gold data in RAM */
+ memcpy(gold, cmap + MAP_W * MAP_H, MAP_W * MAP_H);
+
+ /* count how many pieces of gold on this map */
+ total_gold = 0;
+ for (uint16_t i = 0; i < MAP_W * MAP_H; i++)
+ /* gold is not 0xff */
+ if (gold[i] != 0xff)
+ total_gold++;
}
void map_render()
@@ -30,6 +43,24 @@ void map_render()
blitrc(binary_tiles_start, &src, &dst);
}
+
+ for (uint8_t y = 0; y < MAP_H; y++)
+ for (uint8_t x = 0; x < MAP_W; x++)
+ {
+ dst.x = x * MAP_TILE_W;
+ dst.y = y * MAP_TILE_H + MAP_OFFS_Y;
+
+ uint8_t t = gold[x + y * MAP_W];
+
+ /* not gold, skip! */
+ if (t == 0xff)
+ continue;
+
+ src.x = (t % MAP_TILESET_COLS) * MAP_TILE_W;
+ src.y = (t / MAP_TILESET_COLS) * MAP_TILE_H;
+
+ blitrc(binary_tiles_start, &src, &dst);
+ }
}
uint8_t map_is_blocked(uint16_t x, uint16_t y)
@@ -41,3 +72,38 @@ 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;
}
+
+uint8_t map_update_gold(uint16_t x, uint16_t y)
+{
+ Rect src = { 0, 0, 160, 48 };
+ Rect dst = { 0, 0, 8, 8 };
+
+ uint16_t mx = x / MAP_TILE_W;
+ uint16_t my = y / MAP_TILE_H;
+
+ if (gold[mx + my * MAP_W] != 0xff)
+ {
+ /* this gold is collected */
+ gold[mx + my * MAP_W] = 0xff;
+
+ /* erase the background */
+ dst.x = mx * MAP_TILE_W;
+ dst.y = my * MAP_TILE_H + MAP_OFFS_Y;
+
+ uint8_t t = cmap[mx + my * MAP_W];
+ src.x = (t % MAP_TILESET_COLS) * MAP_TILE_W;
+ src.y = (t / MAP_TILESET_COLS) * MAP_TILE_H;
+
+ blitrc(binary_tiles_start, &src, &dst);
+
+ total_gold--;
+ return 1;
+ }
+
+ return 0;
+}
+
+uint8_t map_is_complete()
+{
+ return total_gold == 0;
+}
diff --git a/src/map.h b/src/map.h
index f36d294..42f8da7 100644
--- a/src/map.h
+++ b/src/map.h
@@ -20,4 +20,7 @@ void map_render();
uint8_t map_is_blocked(uint16_t x, uint16_t y);
uint8_t map_is_deadly(uint16_t x, uint16_t y);
+uint8_t map_update_gold(uint16_t x, uint16_t y);
+uint8_t map_is_complete();
+
#endif /* _MAP_H */
diff --git a/src/player.c b/src/player.c
index 1528337..4fe916e 100644
--- a/src/player.c
+++ b/src/player.c
@@ -4,6 +4,7 @@
#include "vga.h"
#include "map.h"
#include "data.h"
+#include "game.h"
#include "player.h"
@@ -189,6 +190,9 @@ void player_update()
delay = 0;
frame = FRAME_STANDING;
}
+
+ if (map_update_gold(x + (dir == DIR_LEFT ? 7 : 8), y + 15))
+ add_score(10);
}
void player_erase()
diff --git a/tools/map.py b/tools/map.py
index 2f3479a..d4a23a0 100755
--- a/tools/map.py
+++ b/tools/map.py
@@ -42,7 +42,10 @@ def main():
map_layer = get_layer(data, "Map")
- out = map(lambda x: x - tileset["firstgid"], map_layer["data"])
+ out = list(map(lambda x: (x - tileset["firstgid"]) & 0xFF, map_layer["data"]))
+
+ gold_layer = get_layer(data, "Gold")
+ out.extend(map(lambda x: (x - tileset["firstgid"]) & 0xFF, gold_layer["data"]))
# TODO: process map entities