maps: Added ability to add coordinate based flags to maps
authorLukas Krickl <lukas@krickl.dev>
Fri, 4 Jul 2025 15:47:51 +0000 (17:47 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 4 Jul 2025 15:47:51 +0000 (17:47 +0200)
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
src/defs.s
src/player.s
tiles/bank8000.inc
tiles/bank9000.inc
tools/tms2map.py

index f03f814b4bc70745e6e7ae35e06027d80c9d0c2c..ba5a585d65f589da2e2f0e9478ef36465ddd3fd7 100644 (file)
@@ -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
index 33086413f5d0b654f6545ac7490a4a7772b762f6..bbd17479f771e66d7e071b7b6fc40f9d0a4bb9cc 100644 (file)
   ; 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
index f688d46015a67702c9163eb2b934d1d8ba79e1c5..ad5b3c31a25d300f32a67c5f67b0cb57b1d27741 100644 (file)
@@ -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
index 22db67e9025ece4ab880743ef15bc9b9da4c1b29..1662f9dffd8055ce43cdbabca9d62c89fcb4fbe1 100644 (file)
 .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
 .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
index c41637f63d140f1efcc73578340c79d0bc7a9191..cfa01a3a458f78c32003dedc57d8f8d32acc1c00 100644 (file)
 .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
 .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
index b98e9b8f6ffed3ae5bd6b884d8075aa6acc4b365..30a075d55ab4b3349bf28ac3153b6ae713675ba1 100755 (executable)
@@ -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 <source> <map name>")
@@ -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)