Moved animation loading to a macro
authorLukas Krickl <lukas@krickl.dev>
Tue, 26 Nov 2024 07:28:59 +0000 (08:28 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 26 Nov 2024 07:28:59 +0000 (08:28 +0100)
src/actor.s

index 9a32880d8cb5351ebabf64fdb50641e2667145c5..fbda9c9f1277936a07cc8c314e0c52d0da6e22d7 100644 (file)
   ld [actor_soam_ptr], a
 #endmacro
 
+  ; loads an animation frame 
+  ; from a table
+  ; uses hl and a
+  ; inputs:
+  ;   $1: table 
+  ;   $2: max frames (mask)
+  ; returns:
+  ;   a: the frame 
+#macro load_anim_frame
+  ld hl, $1 
+  ld a, [frame_count]
+  and a, $2 ; max frames  
+  ld d, 0
+  ld e, a 
+  add hl, de ; hl = correct tile index 
+  ld a, [hl]
+#endmacro 
+
 actor_anim_table_bat:
 .db BAT_TILE_IDLE1
 .db BAT_TILE_IDLE1
@@ -77,13 +95,7 @@ actor_update_bat:
 
 @skip:
   ; load tile to use into tmp
-  ld hl, actor_anim_table_bat
-  ld a, [frame_count]
-  and a, 0b1111 ; even and odd frames 
-  ld d, 0
-  ld e, a 
-  add hl, de ; hl = correct tile index 
-  ld a, [hl]
+  load_anim_frame actor_anim_table_bat, 0b1111
   ld [tmp], a
 
   ; load oam ptr