From cdfbad1df2d28b8efb2f7fae5850df56ecf6f8ff Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 27 Jul 2023 09:37:53 +0100 Subject: Properly count entities and sure we support enough This accounts: - entities on the map - entities that will be spawn to unlock doors - the time monster --- TODO.md | 1 - src/Makefile | 3 ++- src/entities.c | 2 +- tools/map.py | 9 +++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 42a186f..29fee2b 100644 --- a/TODO.md +++ b/TODO.md @@ -11,4 +11,3 @@ # REVIEW -- map: count entities (currently not taking into account doors!) diff --git a/src/Makefile b/src/Makefile index 6984376..0295073 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,8 +34,9 @@ palette.o: ../data/sprites.png $(IMG_OBJS): %.o: ../data/%.png ../tools/pngpix.py $< $@ +# max-ents is MAX_ENTITY - 1 to account for the time monster $(MAP_OBJS): %.o: ../data/%.json - ../tools/map.py --max-ents 15 $< $@ + ../tools/map.py --max-ents 19 $< $@ $(WAV_OBJS): %.o: ../data/%.wav ../tools/raw.py $< $@ diff --git a/src/entities.c b/src/entities.c index 6b6c7a1..27d565a 100644 --- a/src/entities.c +++ b/src/entities.c @@ -9,7 +9,7 @@ #include "effect.h" -#define MAX_ENTITY 16 +#define MAX_ENTITY 20 static Entity entities[MAX_ENTITY]; static uint8_t last; diff --git a/tools/map.py b/tools/map.py index c959c50..8ead427 100755 --- a/tools/map.py +++ b/tools/map.py @@ -23,6 +23,9 @@ entity_types = ( "SilverKey", ) +# these tiles are part of a door and will use an entity to unlock +tiles_to_entity = (45, 47) + def get_layer(data, name): for layer in data["layers"]: @@ -72,6 +75,7 @@ def main(): map_layer = get_layer(data, "Map") out = list(map(lambda x: (x - tileset["firstgid"]) & 0xFF, map_layer["data"])) + door_cnt = sum(map(lambda x: 1 if x in tiles_to_entity else 0, out)) gold_layer = get_layer(data, "Gold") @@ -90,8 +94,9 @@ def main(): # should help the drawing order in the game objs_sorted = sorted(entity_layer["objects"], key=lambda o: o["y"]) - if args.max_ents and len(objs_sorted) > args.max_ents: - parser.error("Too many entities (limit: %s)" % args.max_ents) + total_ents = len(objs_sorted) + door_cnt + if args.max_ents and total_ents > args.max_ents: + parser.error("Too many entities %d (limit: %s)" % (total_ents, args.max_ents)) for ent in objs_sorted: try: -- cgit v1.2.3