wip: Added bat actor and move duplicate actor code to macros
authorLukas Krickl <lukas@krickl.dev>
Wed, 20 Nov 2024 15:14:18 +0000 (16:14 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 20 Nov 2024 15:14:18 +0000 (16:14 +0100)
src/actor.s
src/wram.s

index b23b5c36ca9c92426c689702f3c9f25b41e6a02a..11dfe2a2111ce8f311bf048080dcfc95ce2ef649 100644 (file)
@@ -1,37 +1,83 @@
 
+  ; skips actor if acto != who
+  ; returns:
+  ;   nz: if actor is not who
+#macro actor_check_who
+  ; if who is current actor simply
+  ; skip
+  ld a, [act]
+  ld d, a
+  ld a, [who]
+  cp a, d
+#endmacro 
+
+  ; skips a turn by calling turn_finish
+  ; and who_next
+#macro actor_skip_turn
+  call turn_finish 
+  call who_next
+#endmacro 
+
 ; function ptrs for each actor type 
 ; inputs:
 ;   bc: actor ptr
 ; actor_soam_ptr: next soam item 
 actor_update_table:
   dw actor_update_null
+  dw actor_update_bat
   dw actor_update_rock
 
 actor_update_null:
-  ; if who is current actor simply
-  ; skip
-  ld a, [act]
-  ld b, a
-  ld a, [who]
-  cp a, b
+  actor_check_who
   jr nz, @skip REL
   
-  call turn_finish 
-  call who_next
+  actor_skip_turn
+@skip:
+  ret
+  
+  ; bat actor 
+actor_update_bat:
+  actor_check_who
+  jr nz, @skip REL
+
+  actor_skip_turn
 
 @skip:
+  ; load oam ptr 
+  ld a, [actor_soam_ptr]
+  ld h, a
+  ld a, [actor_soam_ptr+1]
+  ld l, a
+  
+  inc bc ; bc = actor_y 
+
+  ld a, [bc] ; a = y
+  ld [hl+], a ; set y
+  inc bc
+
+  ld a, [bc] ; a = x
+  ld [hl+], a ; set x
+
+  ld a, PLAYER_TILE_IDLE1
+  ld [hl+], a
+  
+  xor a, a
+  ld [hl+], a
+  
+  ; store soam ptr again
+  ld a, l
+  ld [actor_soam_ptr+1], a
+  ld a, h
+  ld [actor_soam_ptr], a
+
   ret
 
+  ; rock actor
 actor_update_rock:
-
-  ld a, [act]
-  ld d, a
-  ld a, [who]
-  cp a, d
+  actor_check_who 
   jr nz, @skip REL
   
-  call turn_finish
-  call who_next
+  actor_skip_turn
 
 @skip:
 
@@ -62,11 +108,6 @@ actor_update_rock:
   ld a, h
   ld [actor_soam_ptr], a
 
-
-  ; check player collision 
-  ; if collision occured 
-  ; set collision flag
-
   ret
 
   ; updates all active actors from 
index e4a8119cd239ffdd389f89dc2188c9ab67f15b01..58b8a32630e7ba894464678cd728f5bf1eff3897 100644 (file)
@@ -20,7 +20,8 @@ prev_inputs: .adv 1
 .se 0
   ; null actor type = nop
 .de ACTOR_TYPE_NULL, 1
-.de ACTOR_TYPE_DUST, 1
+.de ACTOR_TYPE_BAT, 1
+.de ACTOR_TYPE_ROCK, 1
 
 ; struct actor 
 .se 0