From 5ac890d283630e833c37bf15fc484b688bf24713 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Fri, 29 Nov 2024 09:10:39 +0100 Subject: [PATCH] WIP: bat movement --- src/actor.s | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---- src/rand.s | 2 ++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/actor.s b/src/actor.s index 7b1f220..ff73f3b 100644 --- a/src/actor.s +++ b/src/actor.s @@ -16,7 +16,7 @@ ; skips a turn by calling turn_finish ; and who_next -#macro actor_skip_turn +#macro actor_end_turn turn_finish call who_next #endmacro @@ -49,6 +49,30 @@ actor_anim_table_bat: .db BAT_TILE_IDLE2 .db BAT_TILE_IDLE2 + ; generic actor movement calls + ; up, down, left, right + ; inputs: + ; bc: actor_ptr + ; actor_soam_ptr: next soam item +actor_up: + ret + +actor_down: + ld a, ANIM_MOVE_TILE_SIZE + ld [anim_move_y], a + ld a, ANIM_STEP_DOWN + ld [anim_step_y], a + + xor a, a + ld [anim_step_x], a + ld [anim_move_x], a + ret + +actor_left: + ret + +actor_right: + ret ; function ptrs for each actor type ; inputs: @@ -63,7 +87,7 @@ actor_update_null: actor_check_who ret nz - ; actor_skip_turn + ; actor_end_turn turn_finish jp who_next @@ -72,7 +96,38 @@ actor_update_bat: actor_check_who jr nz, @skip REL - actor_skip_turn + ld a, [end_turn] + cp a, 0 + jr z, @no_anim REL + + ; transfer bc into hl + ld a, b + ld h, a + ld a, c + ld l, a + inc hl ; hl = y/x ptr + call anim_move + cp a, 0 ; is animation done? + jr nz, @skip REL + ; play animation at end of turn + call who_next + jr @skip REL ; darw update +@no_anim: + ; move bat in random direction + call rand + and a, 0b11 ; rnadom direction 0-3 + + ; call correct movement setup + cp a, 0 + call z, actor_up + cp a, 1 + call z, actor_down + cp a, 2 + call z, actor_left + cp a, 3 + call z, actor_right + + turn_finish @skip: ; load tile to use into tmp @@ -126,7 +181,7 @@ actor_update_rock: actor_check_who jr nz, @skip REL - actor_skip_turn + actor_end_turn @skip: diff --git a/src/rand.s b/src/rand.s index 067d54e..11e773f 100644 --- a/src/rand.s +++ b/src/rand.s @@ -1,7 +1,9 @@ ; inits the random seed rand_init: xor a, a + ldhi a, rand_table ld a, [srand] + ldlo a, rand_table ld a, [srand+1] ret -- 2.30.2