From 2c314779358aa568174aa69a0c7d674755fd0bbe Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Fri, 4 Jul 2025 17:47:51 +0200 Subject: [PATCH] maps: Added ability to add coordinate based flags to maps Reworked how tile-based flags are read. They are now read from a property called flags with a simple int value. Coordinate based flags are read from layer properties. A layer property with int value called flags_x,y will be or'd with the tile property value to arrive at a final flag value. This can be useful for exits to allow the setting of exit table offsets in the upper nibble of the flags byte. --- maps/default_map.s | 14 +++++----- src/defs.s | 6 +++++ src/player.s | 24 +++++++++++++++++ tiles/bank8000.inc | 64 +++++++++++++++++++++++----------------------- tiles/bank9000.inc | 64 +++++++++++++++++++++++----------------------- tools/tms2map.py | 33 ++++++++++++++++-------- 6 files changed, 125 insertions(+), 80 deletions(-) diff --git a/maps/default_map.s b/maps/default_map.s index f03f814..ba5a585 100644 --- a/maps/default_map.s +++ b/maps/default_map.s @@ -17,15 +17,17 @@ default_map_bg: .db 0x5, 0x60, 0x1, 0x60, 0xf, 0x60, 0x1, 0x60 .db 0xf, 0x60, 0x1, 0x60, 0xf, 0x60, 0x1, 0x60 .db 0xf, 0x60, 0x1, 0x60, 0x2, 0x60, 0x4, 0x44 -.db 0x9, 0x60, 0x1, 0x60, 0x7, 0x60, 0x3, 0x62 -.db 0x5, 0x60, 0x1, 0x60, 0x7, 0x60, 0x3, 0x62 -.db 0x5, 0x60, 0x1, 0x60, 0x7, 0x60, 0x3, 0x62 -.db 0x5, 0x60, 0x1, 0x60, 0xf, 0x60, 0x1, 0x60 +.db 0x8, 0x60, 0x1, 0x6e, 0x1, 0x60, 0x7, 0x60 +.db 0x3, 0x62, 0x4, 0x60, 0x1, 0x6e, 0x1, 0x60 +.db 0x7, 0x60, 0x3, 0x62, 0x5, 0x60, 0x1, 0x60 +.db 0x7, 0x60, 0x3, 0x62, 0x5, 0x60, 0x1, 0x60 .db 0xf, 0x60, 0x1, 0x60, 0xf, 0x60, 0x1, 0x60 -.db 0xf, 0x60, 0x1, 0x62, 0xe, 0x60, 0x1, 0x42 +.db 0xf, 0x60, 0x1, 0x60, 0xf, 0x60, 0x1, 0x62 +.db 0xe, 0x60, 0x1, 0x42 .db 0x00 ; termiante data default_map_tile_flags: .db 0x27, 0x0, 0x4, 0x1, 0x48, 0x0, 0x4, 0x1 -.db 0x89, 0x0 +.db 0x8, 0x0, 0x1, 0x2, 0xf, 0x0, 0x1, 0x3 +.db 0x70, 0x0 .db 0x00 ; termiante data diff --git a/src/defs.s b/src/defs.s index 3308641..bbd1747 100644 --- a/src/defs.s +++ b/src/defs.s @@ -55,6 +55,12 @@ ; cell flags .se 1 .de CF_COLLISION, 1 + ; exit flag + ; if this flag is set + ; the upper nibble is + ; an index into the current map's + ; exit table +.de CF_EXIT, 1 ; cells struct .se 0 diff --git a/src/player.s b/src/player.s index f688d46..ad5b3c3 100644 --- a/src/player.s +++ b/src/player.s @@ -25,6 +25,10 @@ unit_player_update: ld [hl], a pop de + ; check for exit flags + push de + call unit_check_exit_hit + pop de push de call unit_handle_inputs @@ -36,6 +40,26 @@ unit_player_update: ret + ; checks the current tile + ; and checks for exit flags + ; inputs: + ; de: actor +unit_check_exit_hit: + ld hl, act_pos_y + add hl, de ; hl = actor_y + + ld a, [hl+] + ld b, a ; b = y pos + ld a, [hl] ; hl = x pos + ld c, a ; c = x pos + + call map_get_tile + ; a = flags + and a, CF_EXIT + ret z ; if not we bail + + ret + unit_player: st_def 0x00, unit_player_init, st_unit_idle diff --git a/tiles/bank8000.inc b/tiles/bank8000.inc index 22db67e..1662f9d 100644 --- a/tiles/bank8000.inc +++ b/tiles/bank8000.inc @@ -989,23 +989,23 @@ .chr 11122111 .chr 11222221 ; tile 110 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 111 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 112 .chr 00000000 .chr 00000000 @@ -1133,20 +1133,20 @@ .chr 00000000 .chr 00000000 ; tile 126 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 127 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 diff --git a/tiles/bank9000.inc b/tiles/bank9000.inc index c41637f..cfa01a3 100644 --- a/tiles/bank9000.inc +++ b/tiles/bank9000.inc @@ -989,23 +989,23 @@ .chr 11122111 .chr 11222221 ; tile 110 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 111 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 112 .chr 00000000 .chr 00000000 @@ -1133,20 +1133,20 @@ .chr 00000000 .chr 00000000 ; tile 126 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 ; tile 127 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 +.chr 33333333 diff --git a/tools/tms2map.py b/tools/tms2map.py index b98e9b8..30a075d 100755 --- a/tools/tms2map.py +++ b/tools/tms2map.py @@ -17,11 +17,13 @@ actor_table_ptr = "map_actor_table_null" map_name = "noname" NAME_LEN = 8 -FLAGS = { - 'f_collision': 0x01 - } - TILE_FLAGS = [0] * 256 +MAP_W = 16 +MAP_H = 16 + +# set by layer properties +# flags_x,y +BG_FLAGS = [0] * MAP_W * MAP_H if len(sys.argv) < 3: print("Usage: tmx2map.py ") @@ -90,7 +92,7 @@ def print_bg_flags(data, name, layer): split = data.split(",") flags = [] for i, byte in enumerate(split): - flags.append(TILE_FLAGS[int(byte)-1]) + flags.append(TILE_FLAGS[int(byte)-1] | BG_FLAGS[i]) print_data(flags, name, 'tile_flags', convert_none) def print_header(name): @@ -112,9 +114,8 @@ def get_flag(tile): if child.tag == 'properties': for sub_child in child: if sub_child.tag == 'property': - for flag in FLAGS: - if sub_child.attrib['name'] == flag: - TILE_FLAGS[int(tile.attrib['id'])] |= FLAGS[flag] + if sub_child.attrib['name'] == 'flags': + TILE_FLAGS[int(tile.attrib['id'])] |= int(sub_child.attrib['value']) # get all flags and write them to TILE_FLAGS def get_flags(tileset): @@ -153,6 +154,15 @@ def get_map_props(root): return +def read_bg_props(data): + for child in data: + name = child.attrib['name'] + if name.startswith('flags_'): + name = name.replace('flags_', '') + coords = name.split(',') + tile_index = int(coords[1]) * MAP_W + int(coords[0]) + BG_FLAGS[tile_index] = int(child.attrib['value']) + def convert(src, name): tree = ET.parse(src) root = tree.getroot() @@ -163,8 +173,11 @@ def convert(src, name): for child in root: if child.tag == "layer": for data in child: - print_bg_data(data.text, name, child.attrib['name']) - print_bg_flags(data.text, name, child.attrib['name']) + if data.tag == "properties": + read_bg_props(data) + else: + print_bg_data(data.text, name, child.attrib['name']) + print_bg_flags(data.text, name, child.attrib['name']) elif child.tag == "tileset": get_flags(child) -- 2.30.2