From: Lukas Krickl Date: Mon, 15 Dec 2025 21:15:20 +0000 (+0100) Subject: map: wip mapeditor tile loader and directional movement X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=978efe96a45fe409fe63adab1e9704a887fe4c67;p=gbrg%2F.git map: wip mapeditor tile loader and directional movement --- diff --git a/maps/spawn.inc b/maps/spawn.inc index 474b07d..c51b3aa 100644 --- a/maps/spawn.inc +++ b/maps/spawn.inc @@ -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, 0x1 -.db 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,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, 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 diff --git a/src/actor.s b/src/actor.s index 5bcf01f..6f58efa 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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 diff --git a/src/defs.s b/src/defs.s index 5e84090..2fa99ce 100644 --- a/src/defs.s +++ b/src/defs.s @@ -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 diff --git a/src/levels.s b/src/levels.s index 44ea016..57eb1f5 100644 --- a/src/levels.s +++ b/src/levels.s @@ -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: diff --git a/src/macros.inc b/src/macros.inc index 0d2c263..c6d7c94 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -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 diff --git a/src/map.s b/src/map.s index 2831848..418bcd6 100644 --- 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) diff --git a/src/tiles.s b/src/tiles.s index 79d390f..75f5aeb 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -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 diff --git a/src/wram.s b/src/wram.s index e276a3e..9694cc1 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 diff --git a/tools/tmx2map.py b/tools/tmx2map.py index 3b1a75e..82cc34f 100755 --- a/tools/tmx2map.py +++ b/tools/tmx2map.py @@ -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 ") @@ -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: