map: wip refactor map drawing
authorLukas Krickl <lukas@krickl.dev>
Wed, 31 Dec 2025 12:09:29 +0000 (13:09 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 31 Dec 2025 12:09:29 +0000 (13:09 +0100)
src/defs.s
src/levels.s
src/map.s
src/wram.s

index 5b22335e716708a0bc8c10609ca61e7b759c32fc..419389aa07c27b33eb85073d9a702f078ad21247 100644 (file)
 .se 0
 .de TT_EMPTY, 1
 .de TT_OPEN, 1
+
+       ; tile p0 for TT_LOCKED
+       ; 0000nnnn: direction bits locked door (TF_SE, NE, WE, SE)
+       ; nnnn0000: lock level (0-15)
 .de TT_LOCKED, 1
 
+.de TT_WATER, 1
+.de TT_WATER_DEEP, 1
+       
+       ; tile p0 for TT_LAVA
+       ; 0000nnnn: damage level
+.de TT_LAVA, 1
+
+
        ; tile flags0
 .se 1
        ; SOUTH EXIT
        ; EAST EXIT
 .de TF_EE, 8
 
+
        ; tile struct
 .se 0 
 .de t_type, 1  
index 25da458b914cdd76f1b698fe733b37d98e9f6012..c63ed87e53871f6a6cdc51f1c08bb49eb9a2e19f 100644 (file)
@@ -19,7 +19,13 @@ l1_acts:
        .db 0 ; terminate
        
 l1_tile_props:
-       maptpdef TT_LOCKED, 1, 0, 0, 0, 0
+       maptpdef TT_LOCKED,\
+               1,\
+               0,\
+               0,\
+               0,\
+               (1 << 4) | TF_SE
+
        .db 0 ; terminate
 
 tile_banks_default:
index f1a75307a68570149e5ae67c60b952803b549aaf..c2378dd6df5e3cb3f8965399398b8bd19dd63d54 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -508,6 +508,40 @@ map_full_draw_oam_clear:
        call OAMDMAFN
        ret
        
+       ; gets the direction vector
+       ; for the current player direction
+       ; inputs:
+       ;               player actor 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
+
+       cp a, SOUTH
+       jp z, @south
+
+       cp a, NORTH
+       jp z, @north
+       
+       cp a, WEST
+       jp z, @west
+       
+       ; default case east
+@east:
+       ret
+
+@south:
+       ret
+
+@north:
+       ret
+
+@west:
+       ret
+
+
+       
        ; draws a full map copy into the current map view buffer
        ; bsed on the current location the player is facing
        ; the map render buffer is then written to the screen
@@ -521,9 +555,13 @@ map_full_draw_oam_clear:
        ;               render_buffer: new map data to be drawn
        ; transferts to redraw state
 map_full_draw:
-       ; now we can draw the map
+       ; TODO: remove this call once all references to the 
+       ;                         wram values are removed
+       ;  now we can draw the map
        call map_full_draw_count_forward_attributes
 
+       call _map_full_draw_get_dir_vector
+
        ld a, [tmp_map_forward]
        cp a, MAP_NO_DOOR
        jp z, @short_wall
index 4bbb29e3a2158c49d0adc61fceb64a375f99e1d4..70941ba6cae1f9c1c9d52477618f02a5120193f3 100644 (file)
@@ -108,6 +108,10 @@ update_tile_ptr: .adv 2
 render_buffer: .adv RENDER_BUF_TILES
 minimap_buffer: .adv 9
 
+       ; TODO: refactor map draw to not use 
+       ; these tmps or tile_near far etc
+       ; it should just use tile_direction_vector
+       ; to read tiles ahead
 tmp_map_forward: .adv 1
 tmp_map_near_left_door: .adv 1
 tmp_map_near_right_door: .adv 1
@@ -116,6 +120,7 @@ tmp_map_far_right_door: .adv 1
 tmp_map_furthest_left_door: .adv 1
 tmp_map_furthest_right_door: .adv 1
 
+       ; tmeporary actor position backup
 tmp_act_y: .adv 1
 tmp_act_x: .adv 1
 
@@ -125,5 +130,16 @@ tile_near: .adv 2
 tile_far: .adv 2
 tile_furthest: .adv 2
        
+       ; current tile direction vector
+       ; y and x direction for player
+       ; 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
+       
        ; combat data
 combat: .adv combat_size