map: wip mapeditor tile loader and directional movement
authorLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 21:15:20 +0000 (22:15 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 21:15:20 +0000 (22:15 +0100)
maps/spawn.inc
src/actor.s
src/defs.s
src/levels.s
src/macros.inc
src/map.s
src/tiles.s
src/wram.s
tools/tmx2map.py

index 474b07d26abbee062ef2af1484375ebba4f4caad..c51b3aadcb7bcf56a1390f9661b813921668a9ba 100644 (file)
@@ -1,37 +1,16 @@
 ; this map was generated by tmx2map.py
 
-.db 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
-.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1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, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x10
+.db 0x7, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0x8
index 5bcf01f461876b49952cd74110ec89e0652b5154..6f58efa9082c7db0d26d8c5a0c609ff9578fb071 100644 (file)
@@ -83,7 +83,7 @@ act_can_move:
        pop hl ; hl = flags table
        add hl, de
        ld a, [hl] ; a = required flag
-
+       
        and a, b
 
        ret
@@ -172,6 +172,25 @@ act_move_forward:
        ; inputs:
        ;               de: actor
 act_move_back:
+       ld hl, act_dir
+       add hl, de ; hl = act_dir
+       ld a, [hl]
+       and a, ACT_DIR_MASK
+       ld b, 0
+       ld c, a ; bc = direction offset
+       
+       ; get reverse direction
+       ld hl, act_dir_reverse
+       add hl, bc
+       ld c, [hl] ; bc = reverse offset
+
+
+       ld hl, act_dir_vector
+       add hl, bc ; hl = direction vector
+       ld b, [hl] ; b = direction
+
+       call act_apply_vec
+       
        ret
 
 
index 5e84090aa634a9778185ef6f77ec22e7e6b59833..2fa99ce890ab3cbf6f19408a3de90690a8fd95ff 100644 (file)
@@ -77,7 +77,6 @@
   ; note that tile_bank1 and tile_bank2 are 128 bytes each
   ; whereas bank0 and bank3 are 256 bytes
 .de map_tile_bank_table, 2
-.de map_tile_id_table, 2
 .de map_header_size, 0
        ; the map header is followed by MAP_W * MAP_H bytes
 .de map_tiles, MAP_W * MAP_H
@@ -87,9 +86,6 @@
 .se 0
 .de TT_EMPTY, 1
 .de TT_WALL, 1
-       ; exit tiles store index in exit table
-       ; in p0
-.de TT_EXIT, 1
 
        ; tile flags
 .se 1
index 44ea0169d1e3173b08ee1d8fbba0f9af7459220d..57eb1f5c9de0da9f12516304663e9f42c9af231b 100644 (file)
@@ -9,7 +9,7 @@
        ; where each tile has values and its current state. The map can be drawn from this.
 
 l1:
-       mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default, tile_id_table
+       mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default 
 #include "spawn.inc"
 
 tile_banks_default:
index 0d2c2630576749419af1171d2064eec56b812f6c..c6d7c941910c99c04a062478de0ce509ba5c9bc1 100644 (file)
@@ -156,13 +156,11 @@ $1:
        ;               $2: map routine
        ;               $3: actors
        ;               $4: tile bank table
-       ;               $5: tile id table
 #macro mapdef
        .db $1
        dw $2
        dw $3
        dw $4
-       dw $5
 #endmacro
        
        ; define a tile
index 2831848859b1fcb3e9391740343a287ce8b7f5c9..418bcd6ee8b219960901a1f141b66106896fc782 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -104,15 +104,6 @@ map_settings_load:
        ; inputs:
        ;               de: map ptr
 map_tiles_load:
-       ld hl, map_tile_id_table
-       add hl, de
-       ; store tile id table 
-       ; in map_tile_id_table
-       ld a, [hl+]
-       ld [map_tmp_tile_id_table], a
-       ld a, [hl+]
-       ld [map_tmp_tile_id_table+1], a
-
        ld hl, map_tiles
        add hl, de
        push hl
@@ -138,11 +129,6 @@ map_tiles_load:
                ld c, a
 
                ld hl, tile_id_table
-               ld a, [map_tmp_tile_id_table]
-               ld l, a
-               ld a, [map_tmp_tile_id_table+1]
-               ld h, a
-
                add hl, bc ; hl = ptr offset
 
                ; load ptr into de (source)
index 79d390f47e055d6bc5caf82f1f0f4e42460aa23f..75f5aeb801a1a8b5407e5c09d5b62b48a296e373 100644 (file)
@@ -4,11 +4,11 @@
        ; maps from tile ids 
        ; to tile presets (tile index)
 tile_id_table:
-       ; 0 no exits
+       ; 0
        dw tile_no_exits
-       ; 1 all exit flags set
+       ; 1 
        dw tile_all_exit
-       ; 2 south exit
+       ; 2
        dw tile_south_exit
        ; 3
        dw tile_north_exit
@@ -16,11 +16,37 @@ tile_id_table:
        dw tile_west_exit
        ; 5
        dw tile_east_exit
+
        ; 6
        dw tile_north_south_exit
        ; 7
+       dw tile_north_east_exit
+       ; 8
+       dw tile_north_west_exit
+       
+       ; 9 
+       dw tile_south_west_exit
+       ; A
+       dw tile_south_east_exit
+
+       ; B
        dw tile_east_west_exit
 
+       ; C
+       dw tile_north_south_west_exit
+
+       ; D
+       dw tile_south_west_east_exit
+       
+       ; E
+       dw tile_north_south_east_exit
+
+       ; F
+       dw tile_north_east_west_exit
+
+       ; 10
+       dw tile_north_west_south_exit
+
        
        ; fallback tile 
 tile_null:
@@ -46,4 +72,29 @@ tile_north_south_exit:
 tile_east_west_exit:
        tiledef TT_WALL, TF_EE | TF_WE, 0 
        
+tile_north_east_exit:
+       tiledef TT_WALL, TF_EE | TF_NE, 0 
+
+tile_north_west_exit:
+       tiledef TT_WALL, TF_WE | TF_WE, 0 
+
+tile_south_east_exit:
+       tiledef TT_WALL, TF_EE | TF_SE, 0 
+
+tile_south_west_exit:
+       tiledef TT_WALL, TF_SE | TF_WE, 0 
+
+tile_north_south_east_exit:
+       tiledef TT_WALL, TF_NE | TF_SE | TF_EE, 0 
+
+tile_north_south_west_exit:
+       tiledef TT_WALL, TF_NE | TF_SE | TF_WE, 0 
+
+tile_south_west_east_exit:
+       tiledef TT_WALL, TF_SE | TF_WE | TF_EE, 0 
+
+tile_north_east_west_exit:
+       tiledef TT_WALL, TF_EE | TF_WE | TF_NE, 0 
 
+tile_north_west_south_exit:
+       tiledef TT_WALL, TF_SE | TF_NE | TF_WE, 0 
index e276a3e6c68bf9cec2543e9ffbd368bcee2e319b..9694cc1dbc359ac0e8905835fbcff42db171aa45 100644 (file)
@@ -89,7 +89,6 @@ map: .adv 2
        ; ptr to top left corner of SCRN
        ; where the map should be drawn
 map_vram_tl: .adv 2
-map_tmp_tile_id_table: .adv 2
        ; exit table
        ; an exit table always has 4 entries
        ; exits usually transition using a scroll
index 3b1a75eaeb6989fb55d5c1b318cbe0d746fc5720..82cc34fb9101081e6298f1557a7c4f17161600b0 100755 (executable)
@@ -4,6 +4,7 @@ import os
 import xml.etree.ElementTree as ET
 
 TILE_SIZE = 8
+MAP_W = 20
 
 if len(sys.argv) < 2:
        print("Usage: tmx2map.py <source>")
@@ -12,17 +13,6 @@ if len(sys.argv) < 2:
 
 src = sys.argv[1]
 
-tile_id_table = {
-       1: 0,
-       2: 1,
-       3: 2,
-       4: 3,
-       5: 4,
-       6: 5,
-       7: 6,
-       8:7 
-}
-
 default_tile_id = 0
 
 def print_bg_data(data):
@@ -31,18 +21,13 @@ def print_bg_data(data):
 
        for i, b in enumerate(split):
                end = ', '
-               if i % 8 == 0:
+               if i % MAP_W == 0:
                        print("\n.db ", end = '')
 
 
-               val = int(b.strip())
-               if val in tile_id_table:
-                       val = tile_id_table[val]
-               else:
-                       print("Warning: ", val, " is not found in tile id map", file=sys.stderr)
-                       val = default_tile_id
+               val = int(b.strip()) - 1
 
-               if (i+1) % 8 == 0:
+               if (i+1) % MAP_W  == 0:
                        end = ''
                
                if i == len(data) - 1: