From 116c07b4a6aeb0424854b4aec6aa763e57a5eade Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 31 Dec 2025 15:12:33 +0100 Subject: [PATCH] map: Added direction vector templates --- src/defs.s | 11 +++++++ src/map.s | 88 ++++++++++++++++++++++++++++++++++++++++++++---------- src/wram.s | 12 ++++---- 3 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/defs.s b/src/defs.s index 419389a..cd15477 100644 --- a/src/defs.s +++ b/src/defs.s @@ -302,3 +302,14 @@ ; if all flags are 0 == normal hit .de combat_res_hit_type, 1 .de combat_size, 0 + + ; dir vector struct + ; contains normal vectors for each direction + ; based on the current facing direction +.se 0 +.de dv_forward, 2 +.de dv_back, 2 +.de dv_left, 2 +.de dv_right, 2 +.de dv_size, 0 + diff --git a/src/map.s b/src/map.s index c2378dd..2ad48d4 100644 --- a/src/map.s +++ b/src/map.s @@ -507,17 +507,60 @@ map_full_draw_oam_clear: ; dma empty oam call OAMDMAFN ret + + ; direction vector templates + ; for each direction + ; y/x coordinates +_dir_vectors_east: + ; forward + .db 0, 1 + ; back + .db 0, -1 + ; left + .db 1, 0 + ; right + .db -1, 0 + +_dir_vectors_west: + ; forward + .db 0, -1 + ; back + .db 0, 1 + ; left + .db -1, 0 + ; right + .db 1, 0 + +_dir_vectors_north: + ; forward + .db 1, 0 + ; back + .db -1, 0 + ; left + .db 0, 1 + ; right + .db 0, -1 + +_dir_vectors_south: + ; forward + .db -1, 0 + ; back + .db 1, 0 + ; left + .db 0, -1 + ; right + .db 0, 1 + + ; gets the direction vector - ; for the current player direction + ; for the current direction + ; copies to common wram location ; inputs: - ; player actor direction + ; a: direction ; returns: - ; tle_dir_vector: set for all directions -_map_full_draw_get_dir_vector: - ld a, [player+act_dir] - and a, ACT_DIR_MASK - + ; dir_vector: set for all directions +map_get_dir_vectors: cp a, SOUTH jp z, @south @@ -529,16 +572,26 @@ _map_full_draw_get_dir_vector: ; default case east @east: - ret + ld de, _dir_vectors_east + ld hl, dir_vectors + ld bc, dv_size + jp memcpy @south: - ret - + ld de, _dir_vectors_south + ld hl, dir_vectors + ld bc, dv_size + jp memcpy @north: - ret - -@west: - ret + ld de, _dir_vectors_north + ld hl, dir_vectors + ld bc, dv_size + jp memcpy +@west: + ld de, _dir_vectors_west + ld hl, dir_vectors + ld bc, dv_size + jp memcpy @@ -559,8 +612,13 @@ map_full_draw: ; wram values are removed ; now we can draw the map call map_full_draw_count_forward_attributes + + ; 1) get player direction vecors + ld a, [player+act_dir] + and a, ACT_DIR_MASK + call map_get_dir_vectors - call _map_full_draw_get_dir_vector + ; 2) draw back to front ld a, [tmp_map_forward] cp a, MAP_NO_DOOR diff --git a/src/wram.s b/src/wram.s index 70941ba..7b714ce 100644 --- a/src/wram.s +++ b/src/wram.s @@ -131,15 +131,17 @@ tile_far: .adv 2 tile_furthest: .adv 2 ; current tile direction vector - ; y and x direction for player + ; y and x direction ; this can be used to get all tiles ahead ; by moving in the direction ; mainly used for player attack direction and ; rendering the first person view -tile_dir_vector_forward: .adv 2 -tile_dir_vector_back: .adv 2 -tile_dir_vector_left: .adv 2 -tile_dir_vector_right: .adv 2 +dir_vectors: +dir_vector_forward: .adv 2 +dir_vector_back: .adv 2 +dir_vector_left: .adv 2 +dir_vector_right: .adv 2 +dir_vectors_end: ; combat data combat: .adv combat_size -- 2.30.2