actor: restored actor ability to collide with walls and doors
authorLukas Krickl <lukas@krickl.dev>
Sun, 9 Mar 2025 11:38:07 +0000 (12:38 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 9 Mar 2025 11:38:07 +0000 (12:38 +0100)
src/actor.s
src/player.s
src/state.s

index f5303c2ad56afe18937e94fd7a66e93b5243a23d..fe0abc650d07a30bf6c79c14d500fea422072e78 100644 (file)
@@ -206,6 +206,51 @@ draw_cursor:
 
   ret
 
+  ; generic collision check code
+  ; loads ct_mask and actor position 
+  ; and calls collision tile
+  ; inputs:
+  ;   bc: actor ptr
+  ;   de: y/x position offset 
+  ; returns:
+  ;   a/h: collision flags 
+generic_collision_check:
+  ; load actor y/x into de
+  inc bc ; bc = actor y
+  ld a, [bc]
+  add a, d ; y + offset 
+
+  ld d, a ; d = target y
+  inc bc ; bc = actor x
+  ld a, [bc]
+  add a, e ; x + offset 
+  ld e, a ; e = target x
+
+  ; if any collision happens now 
+  ; we stop the animation
+  call collision_tile 
+  ld h, a ; store original a in h for now 
+  ret
+
+  ; performs a simple collision check for actors
+  ; inputs:
+  ;   bc: actor ptr
+  ;   de: y/x position offset 
+act_collision_check:
+  ; set collision mask
+  ld a, RF_WALL | RF_ACTOR | RF_DOOR
+  ld [ct_mask], a
+
+  call generic_collision_check
+  
+  and a, RF_WALL | RF_ACTOR | RF_DOOR
+  jr z, @skip REL
+    ; abort walk state 
+    call anim_abort_walk
+    jr @skip REL
+@skip:
+  ret
+
   ; advance to the next actor if end_turn != 0
   ; effectively ending the current actor's turn
 who_next:
index 947ccf58f3e7ae338e86aa7fa1da281c8a9ccc87..328fafd8837b83a54f12f4630792a1544525b39b 100644 (file)
@@ -193,26 +193,11 @@ player_update:
   ;   bc: actor ptr
   ;   de: y/x position offset 
 player_collision_check:
-
   ; set collision mask
   ld a, RF_WALL | RF_DOOR | RF_ACTOR
   ld [ct_mask], a
-
-  ; load actor y/x into de
-  inc bc ; bc = actor y
-  ld a, [bc]
-  add a, d ; y + offset 
-
-  ld d, a ; d = target y
-  inc bc ; bc = actor x
-  ld a, [bc]
-  add a, e ; x + offset 
-  ld e, a ; e = target x
-
-  ; if any collision happens now 
-  ; we stop the animation
-  call collision_tile 
-  ld h, a ; store original a in h for now 
+  
+  call generic_collision_check
 
   and a, RF_DOOR
   jr z, @no_door_hit REL
@@ -221,7 +206,6 @@ player_collision_check:
   ld a, [engine_flags]
   or a, EG_FLOAD_ROOM 
   ld [engine_flags], a
-  
 
 @no_door_hit:
 
index 727a949e13bafa2346323be1983c6463a739b408..326d8271333fa4624543650bc8e9ef2ed42ffe8e 100644 (file)
@@ -159,6 +159,11 @@ sm_bat_pick_direction:
     ld [hl+], a ; set next state
     ld a, ANIM_PLAYER_WALK_FRAMES
     ld [hl], a ; set param[0]
+
+    ; perform collision check
+    ld d, 0xFF & 0 - ANIM_TILE_SIZE 
+    ld e, 0
+    call act_collision_check
 @not_north:
 
   cp a, SOUTH
@@ -170,6 +175,10 @@ sm_bat_pick_direction:
     ld a, ANIM_PLAYER_WALK_FRAMES
     ld [hl], a ; set param[0]
 
+    ; perform collision check
+    ld d, ANIM_TILE_SIZE 
+    ld e, 0
+    call act_collision_check
 @not_south:
 
   cp a, WEST
@@ -181,6 +190,10 @@ sm_bat_pick_direction:
     ld a, ANIM_PLAYER_WALK_FRAMES
     ld [hl], a ; set param[0]
 
+    ; perform collision check
+    ld d, 0
+    ld e, 0xFF & 0 - ANIM_TILE_SIZE 
+    call act_collision_check
 @not_west:
 
   cp a, EAST
@@ -192,6 +205,10 @@ sm_bat_pick_direction:
     ld a, ANIM_PLAYER_WALK_FRAMES
     ld [hl], a ; set param[0]
 
+    ; perform collision check
+    ld d, 0
+    ld e, ANIM_TILE_SIZE 
+    call act_collision_check
 @not_east:
 
   ; verify collision