actor: Added collision checks
authorLukas Krickl <lukas@krickl.dev>
Wed, 3 Dec 2025 09:48:45 +0000 (10:48 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 3 Dec 2025 09:48:45 +0000 (10:48 +0100)
The current implementation still stops x movement when there is no x collision.

src/actor.s
src/levels.s

index 4157470728f1d4e547f76738ad0e4e72cb27321e..823071835df171bdea848225f8c5fdb22dad31ba 100644 (file)
@@ -77,39 +77,40 @@ act_test_tile_collision:
        ;               $1: point name
        ; returns:
        ;               b/c: y/x tile position
-#macro _act_tile_col_load_pt
+#macro _act_col_load_pt
        ld a, [$1]
-       div16 a
        ld b, a
        ld a, [$1+1]
-       div16 a
        ld c, a
 #endmacro
        
-       ; test direction routines:
-       ;       preserve: de
-_act_test_tile_left_collision:
-       push de
-
-       ; top left point
-       _act_tile_col_load_pt col_point_tl
+       ; checks collision
+       ; inputs:
+       ;               $1: point to check
+       ;               $2: label to jump to (jr)
+#macro _act_tile_col_check
+       _act_col_load_pt $1
+       div16 b
+       div16 c
 
        call map_get_tile
        ld de, t_flags
        add hl, de
        ld a, [hl]
        and a, TF_WALL
-       jr nz, @collision REL
+       jr nz, $2 REL
+#endmacro
+       
+       ; test direction routines:
+       ;       preserve: de
+_act_test_tile_left_collision:
+       push de
 
-       ; bottom left point
-       _act_tile_col_load_pt col_point_bl
+       ; top left point
+       _act_tile_col_check col_point_tl, @collision
 
-       call map_get_tile
-       ld de, t_flags
-       add hl, de
-       ld a, [hl]
-       and a, TF_WALL
-       jr nz, @collision REL
+       ; bottom left point
+       _act_tile_col_check col_point_bl, @collision
 
        pop de
        ret
@@ -121,17 +122,49 @@ _act_test_tile_left_collision:
 _act_test_tile_right_collision:
        push de
 
+       ; top right point
+       _act_tile_col_check col_point_tr, @collision
+
+       ; bottom right point
+       _act_tile_col_check col_point_br, @collision
+
+       pop de
+       ret
+@collision:
        pop de
+       call act_rollback_pos_x
        ret
 
 _act_test_tile_up_collision:
        push de
+       
+       ; top left point
+       _act_tile_col_check col_point_tl, @collision
+
+       ; top right point
+       _act_tile_col_check col_point_tr, @collision
+
        pop de
        ret
+@collision:
+       pop de
+       call act_rollback_pos_y
+       ret
 
 _act_test_tile_down_collision:
        push de
+
+       ; bottom left point
+       _act_tile_col_check col_point_bl, @collision
+
+       ; bottom rihgt point
+       _act_tile_col_check col_point_br, @collision
+
+       pop de
+       ret
+@collision:
        pop de
+       call act_rollback_pos_y
        ret
 
        ; update routines for each actor
index e6a66cb6afb17823591f8ce6bab3efb339ec3b12..78fc062fd605f1d500a9d15008611b02ddc38021 100644 (file)
@@ -17,7 +17,7 @@ l1:
        .db TWL, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
-       .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
+       .db TGS, TGS, TGS, TGS, TWL, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS
        .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TWL