Added test animation for bats
authorLukas Krickl <lukas@krickl.dev>
Fri, 29 Nov 2024 09:05:34 +0000 (10:05 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 29 Nov 2024 09:05:34 +0000 (10:05 +0100)
src/actor.s
src/rand.s

index ff73f3b4a2c623511067a1c65ae293b03b3eca6c..22e5eca8081048160f68425e13c550dc5dd7db75 100644 (file)
@@ -55,6 +55,14 @@ actor_anim_table_bat:
   ;   bc: actor_ptr
   ; actor_soam_ptr: next soam item
 actor_up:
+  ld a, ANIM_MOVE_TILE_SIZE
+  ld [anim_move_y], a
+  ld a, ANIM_STEP_UP
+  ld [anim_step_y], a
+
+  xor a, a
+  ld [anim_step_x], a
+  ld [anim_move_x], a
   ret
 
 actor_down:
@@ -69,9 +77,25 @@ actor_down:
   ret
 
 actor_left:
+  ld a, ANIM_MOVE_TILE_SIZE
+  ld [anim_move_x], a
+  ld a, ANIM_STEP_LEFT
+  ld [anim_step_x], a
+
+  xor a, a
+  ld [anim_step_y], a
+  ld [anim_move_y], a
   ret
 
 actor_right:
+  ld a, ANIM_MOVE_TILE_SIZE
+  ld [anim_move_x], a
+  ld a, ANIM_STEP_RIGHT
+  ld [anim_step_x], a
+
+  xor a, a
+  ld [anim_step_y], a
+  ld [anim_move_y], a
   ret
 
 ; function ptrs for each actor type 
@@ -106,11 +130,14 @@ actor_update_bat:
   ld a, c
   ld l, a
   inc hl ; hl = y/x ptr
+  push bc
   call anim_move
+  pop bc
   cp a, 0 ; is animation done?
   jr nz, @skip REL
   ; play animation at end of turn
   call who_next
+  call anim_clear
   jr @skip REL ; darw update 
 @no_anim:
   ; move bat in random direction
@@ -300,6 +327,14 @@ anim_move:
 
   ret
 
+  ; clear anim memory
+anim_clear:
+  xor a, a
+  ld [anim_move_y], a
+  ld [anim_move_x], a
+  ld [anim_step_y], a
+  ld [anim_step_x], a
+  ret
 
   ; advance to the next actor if end_turn != 0
   ; effectively ending the current actor's turn
index 11e773ff6f8e0f1d5e926d6e911e0ac0a0ba9659..29b305d6a89a40d951f805e194a1bbb5f9d49bb5 100644 (file)
@@ -1,9 +1,7 @@
   ; 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
 
@@ -12,7 +10,7 @@ rand_init:
   ; gets a pseudo-random number
   ; and advances to the next seed
   ; uses:
-  ;   hl, a, b
+  ;   hl, a, b, de
   ; returns:
   ;   a: random value
 rand:
@@ -29,7 +27,9 @@ rand:
   ld a, h
   and a, ((rand_table_end - rand_table - 1) >> 8); overflow at max size 
   ld [srand], a
-
+  
+  ld de, rand_table
+  add hl, de
   ld a, [hl] ; next value 
   ret