actor: added temporary pre-calculation for rectangle points
authorLukas Krickl <lukas@krickl.dev>
Fri, 26 Sep 2025 06:48:28 +0000 (08:48 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 26 Sep 2025 06:48:28 +0000 (08:48 +0200)
src/actor.s
src/wram.s

index 9f8545d85fe8dc6c1f1c5e56f608dbff9299dfee..aa7fad3791673363b01331fc82df19b93588bff3 100644 (file)
@@ -210,6 +210,8 @@ actor_test_movement:
 
        ld a, b
        ld [tmp_act_direction], a
+       ; a = direction
+       call actor_test_movement_write_points
 
        ; check all static rectangles
        ld hl, rectangles
@@ -277,6 +279,61 @@ actor_test_movement:
        ; hl = actor already 
        ld a, 1
        ret
+       
+       ; writes a point to a rectangle
+       ; inputs:
+       ;               hl: rectangle
+       ;               bc: tmp_rect_points ptr
+       ;               $1 rect_tr,bl,br,tl
+#macro act_test_movement_write_point_at
+       push hl
+       push bc
+       call $1
+       pop bc
+       pop hl
+
+       ld a, d
+       ld [bc], a
+       inc bc
+       ld a, e
+       ld [bc], a
+       inc bc
+#endmacro
+
+       ; writes tmp rect points to 
+       ; tmp_rect_points. only writes 2 points 
+       ; based on the chosen direction
+       ; inputs:
+       ;               a: direction
+       ;               tmp_rect: the rectangle
+actor_test_movement_write_points:
+       ld hl, tmp_rect
+       ld bc, tmp_rect_points
+
+       cp a, DIRDOWN
+       jp z, @down
+       cp a, DIRLEFT
+       jp z, @left
+       cp a, DIRRIGHT
+       jp z, @right
+       
+       ; default case: up
+@up:
+       act_test_movement_write_point_at rect_tl
+       act_test_movement_write_point_at rect_tr
+       ret
+@down:
+       act_test_movement_write_point_at rect_bl 
+       act_test_movement_write_point_at rect_br 
+       ret
+@right:
+       act_test_movement_write_point_at rect_br 
+       act_test_movement_write_point_at rect_tr 
+       ret
+@left:
+       act_test_movement_write_point_at rect_bl 
+       act_test_movement_write_point_at rect_tl 
+       ret
 
        ; tests a single rectangle against an actor 
        ; based on the current direction only 2 points are tested
index 41420f9b35d389fdf284e3e1535f30532e8bc9b0..5ba82e9cf02df72d8bf255601296bbe02f9fd029 100644 (file)
@@ -84,6 +84,11 @@ rectangles: .adv r_size * RECT_MAX
 tmp_rect: .adv r_size
 tmp_rect_mask: .adv 1
        
+       ; temporary points 
+       ; has enough space for 4 points
+       ; store pre-calculated points here for collision checking
+tmp_rect_points: .adv 4 * 2
+       
        ; temporary actor direction mask
 tmp_act_direction: .adv 1