WIP: bat movement
authorLukas Krickl <lukas@krickl.dev>
Fri, 29 Nov 2024 08:10:39 +0000 (09:10 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 29 Nov 2024 08:10:39 +0000 (09:10 +0100)
src/actor.s
src/rand.s

index 7b1f220321bd7fefa0996b828f6e2190b445d960..ff73f3b4a2c623511067a1c65ae293b03b3eca6c 100644 (file)
@@ -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:
 
index 067d54e38a75d376f6e371998d8247b2d56cfa07..11e773ff6f8e0f1d5e926d6e911e0ac0a0ba9659 100644 (file)
@@ -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