Added simple player animation
authorLukas Krickl <lukas@krickl.dev>
Tue, 26 Nov 2024 14:07:01 +0000 (15:07 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 26 Nov 2024 14:07:01 +0000 (15:07 +0100)
src/actor.s
src/player.s

index fbda9c9f1277936a07cc8c314e0c52d0da6e22d7..7b1f220321bd7fefa0996b828f6e2190b445d960 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
@@ -66,7 +48,6 @@ actor_anim_table_bat:
 .db BAT_TILE_IDLE2
 .db BAT_TILE_IDLE2
 .db BAT_TILE_IDLE2
-.db BAT_TILE_IDLE2
 
 
 ; function ptrs for each actor type 
index 9fb75ee7b7979a9ad1d922b030062d8931e69ac1..39a928f7f91949a0409df7501f72e29e556768f6 100644 (file)
@@ -4,6 +4,14 @@
 .def int PLAYER_TILE_IDLE1 = 0x00
 .def int PLAYER_TILE_IDLE2 = 0x12
 
+.def int PLAYER_TILE_MOVE_FRAME1_1 = 0x02
+.def int PLAYER_TILE_MOVE_FRAME2_1 = 0x10
+
+player_anim_table1:
+.rep c, 2, 1, .db PLAYER_TILE_IDLE1 
+.rep c, 7, 1, .db PLAYER_TILE_MOVE_FRAME1_1 
+.rep c, 7, 1, .db PLAYER_TILE_MOVE_FRAME2_1 
+
 #define PLAYER_IFRAME_TIMER 64
 #define DAMAGE_ANIM_LEN 20
 
@@ -56,7 +64,7 @@ player_init:
   push de
    
   ; 2) hl = player_y already 
-  ; 3) load correct collision points 
+; 3) load correct collision points 
   ld de, $1 
   call collision_tile_table_check
   pop de 
@@ -289,6 +297,12 @@ player_update:
 
   ret
 @draw_visible:
+  ; load left tile into tmp
+  push de
+  load_anim_frame player_anim_table1, 0b1111
+  ld [tmp], a
+  pop de
+
   ; drawing 
 
   ; set up obj flag mask based on frame counter 
@@ -310,7 +324,7 @@ player_update:
   ld [hl+], a
 
   ; idel tile 1
-  ld a, PLAYER_TILE_IDLE1 
+  ld a, [tmp] 
   ld [hl+], a
 
   ; flags