From 21672c5cdec39b4bf6fab34a6ef88c0619ba7670 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 6 Mar 2025 21:10:37 +0100 Subject: [PATCH] bat: bats now pick a random direction to walk in again Bats can now move on their own again, but they do not perform collision checks nor mark tiles as occupied yet. --- src/actor.s | 2 +- src/state.s | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/actor.s b/src/actor.s index 6026260..356fbfb 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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 diff --git a/src/state.s b/src/state.s index 64be0cc..727a949 100644 --- a/src/state.s +++ b/src/state.s @@ -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 -- 2.30.2