bat: bats now pick a random direction to walk in again
authorLukas Krickl <lukas@krickl.dev>
Thu, 6 Mar 2025 20:10:37 +0000 (21:10 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 6 Mar 2025 20:10:37 +0000 (21:10 +0100)
Bats can now move on their own again, but they do not perform collision
checks nor mark tiles as occupied yet.

src/actor.s
src/state.s

index 60262600822a2f5b549c76021927564be514987f..356fbfb307bead725df420821f883c39f1d6333f 100644 (file)
@@ -274,7 +274,7 @@ actor_update_bat:
   jr nz, @skip REL
 
   ; call state update
-  ld a, smt_player_poll_inputs
+  ld a, smt_bat_pick_direction
   ; load initial state if required
   call sm_load_initial_state
   
index 64be0cc64f8423f3e1d7f15600d05b7202ac1b57..727a949e13bafa2346323be1983c6463a739b408 100644 (file)
@@ -140,33 +140,58 @@ sm_player_poll_inputs:
   ; after verifying collision
   ; otherwise -> end turn
 sm_bat_pick_direction:
-  ; hl = sm ptr
-  sm_load_ptr hl
-
   push bc
   ; move bat in random direction
   call rand
   and a, 0b11 ; rnadom direction 0-3
   
+  push af
+  ; hl = sm ptr
+  sm_load_ptr hl
+  pop af
+
   ; call correct movement setup
   cp a, NORTH
   jr nz, @not_north REL
 
+    ; set animation params
+    ld a, smt_actor_go_north 
+    ld [hl+], a ; set next state
+    ld a, ANIM_PLAYER_WALK_FRAMES
+    ld [hl], a ; set param[0]
 @not_north:
 
   cp a, SOUTH
   jr nz, @not_south REL
 
+    ; set animation params
+    ld a, smt_actor_go_south
+    ld [hl+], a ; set next state
+    ld a, ANIM_PLAYER_WALK_FRAMES
+    ld [hl], a ; set param[0]
+
 @not_south:
 
   cp a, WEST
   jr nz, @not_west REL
 
+    ; set animation params
+    ld a, smt_actor_go_west
+    ld [hl+], a ; set next state
+    ld a, ANIM_PLAYER_WALK_FRAMES
+    ld [hl], a ; set param[0]
+
 @not_west:
 
   cp a, EAST
   jr nz, @not_east REL
 
+    ; set animation params
+    ld a, smt_actor_go_east
+    ld [hl+], a ; set next state
+    ld a, ANIM_PLAYER_WALK_FRAMES
+    ld [hl], a ; set param[0]
+
 @not_east:
 
   ; verify collision