actor: added collision checks for tiles that contain an active actor
authorLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 08:41:10 +0000 (09:41 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 08:41:10 +0000 (09:41 +0100)
src/actor.s
src/wram.s

index 1f61e2fef27242f8e83a379143a1b19bf88d84de..0968dfecc708f2d127bf14a9007fbe894a73b280 100644 (file)
@@ -394,12 +394,70 @@ act_apply_pos:
 
        ret
        
+       ; creates a copy of the actors position
+       ; in tmp_act_y and _x
+       ; inputs:
+       ;               de: actor
+       ; preverse:
+       ;               de
+_act_backup_pos:
+       ld hl, act_pos_y
+       add hl, de
+       ld a, [hl+]
+       ld [tmp_act_y], a
+       ld a, [hl]
+       ld [tmp_act_x], a
+       ret
+       
+       ; restores actor position 
+       ; from tmp_act_y/x
+       ; inputs:
+       ;               de: actor
+       ; preserves:
+       ;               de
+_act_restore_pos:
+       ld hl, act_pos_y
+       add hl, de
+
+       ld a, [tmp_act_y]
+       ld [hl+], a
+       ld a, [tmp_act_x]
+       ld [hl], a
+       ret
+       
+       ; tests if the new actor location contains
+       ; an actor
+       ; rolls back position to tmp_act_y/x if it does
+       ; input:
+       ;               de: actor
+       ; preserves:
+       ;               de
+_act_check_act_in_location:
+       push de
+       ld hl, act_pos_y
+       add hl, de
+       ld a, [hl+]
+       ld b, a
+       ld c, [hl]
+       call map_get_tile
+       ; hl = tile
+       ld bc, t_act
+       add hl, bc
+
+       ld a, [hl+]
+       or a, [hl]
+       pop de
+       call nz, _act_restore_pos
+       ret
+       
        
        ; moves the actor forward
        ; performs collision checks
        ; inputs:
        ;               de: actor
 act_move_forward:
+       call _act_backup_pos
+
        push de
        ld hl, act_dir_forward
        call act_can_move
@@ -424,10 +482,10 @@ act_move_forward:
        
        call act_apply_vec
 
-       ; TODO: check if player collides with actor
+       ; check if player collides with actor
        ; at new location
-
        pop de
+       call _act_check_act_in_location
        call act_set_tact
 
        ret
@@ -437,6 +495,8 @@ act_move_forward:
        ; inputs:
        ;               de: actor
 act_move_back:
+       call _act_backup_pos
+
        push de
        ld hl, act_dir_back
        call act_can_move
@@ -468,6 +528,7 @@ act_move_back:
        call act_apply_vec
 
        pop de
+       call _act_check_act_in_location
        call act_set_tact
        
        ret
index d79219b1bacfa75f07f796f371b9f810c37d8fb8..564b36cc5788df9fa77e7927227e3fa261dd0b11 100644 (file)
@@ -130,6 +130,8 @@ tmp_map_near_left_door: .adv 1
 tmp_map_near_right_door: .adv 1
 tmp_map_far_left_door: .adv 1
 tmp_map_far_right_door: .adv 1
+tmp_act_y: .adv 1
+tmp_act_x: .adv 1
        
        ; actor that is adjacent
        ; to the players current facing