animation: Added frame wait state
authorLukas Krickl <lukas@krickl.dev>
Tue, 9 Sep 2025 03:28:56 +0000 (05:28 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 9 Sep 2025 03:28:56 +0000 (05:28 +0200)
TODO.md
src/animation.s
src/defs.s
src/macros.inc
src/unit_demo.s

diff --git a/TODO.md b/TODO.md
index 5a04dc3c1c696113ed113eb1c58020d10947d690..03c6f49b9e7bdd1f6ed6131b4926c672fb9b32c3 100644 (file)
--- a/TODO.md
+++ b/TODO.md
 [ ] destroy doors -> fail may spawn enemy due to noise
 [ ] Sometimes bribery fails
 
+## animations
+
+[ ] make table for each actor type where animations can be looked up
+               e.g. idle for each, walk left, walk right, walk up, walk down, attack etc
+
+[ ] allow sub tile movement by setting up a rt_st_x and _y value in each actor
+               this value will then be inc/dec in special move left, right, up, down wait states
+               this value will be added to the rendered object in unit_draw
index 0af70744a106914768278c6e2daf6d8911dd4adf..879dfc79b571108492b1103c8d1364c5acb6433a 100644 (file)
@@ -1,14 +1,14 @@
 player_anim_table:
+       anim_header 32, player_anim_table_f2
        anim_ent 0, 8, 0x8C, OAM_FXFLIP 
        anim_ent 0, 0, 0x8E, OAM_FXFLIP
        anim_ent 0, 0, 0x00, 0
-       dw player_anim_table_f2
 
 player_anim_table_f2:
+       anim_header 32, player_anim_table
        anim_ent 1, 8, 0x8C, OAM_FXFLIP 
        anim_ent 1, 0, 0x8E, OAM_FXFLIP
        anim_ent 0, 0, 0x00, 0
-       dw player_anim_table
        
        ; translates tile to screen
        ; inputs:
@@ -94,25 +94,48 @@ unit_draw:
        pop af
        ld l, a
        push hl
-       pop bc ; bc = anim talbe entry
+       pop bc 
 
+       ; bc = animation header
+       push bc ; save header for later
+       inc bc
+       inc bc
+       inc bc ; go past header
+       
+       ; bc = anim talbe entry
        call unit_draw_obj
        call unit_draw_obj
        call unit_draw_obj
        
-       ; load next anim table
-       ; every few frames
-       ld a, [frame_count]
-       cp a, 4 
-       jr nz, @no_new_frame REL
+       ; process header
+       pop bc
 
-       ld hl, act_anim_table
-       add hl, de
-       ld a, [bc]
-       ld [hl+], a
-       inc bc
-       ld a, [bc]
-       ld [hl], a
+       ld hl, act_rt_anim_timer
+       add hl, de ; hl = animation timer
+       ld a, [hl]
+       inc a
+       ld [hl], a ; timer++
+       
+       push de
+       ld d, a ; d = current timer
+       ld a, [bc] ; a = expected timer
+       cp a, d ; next frame?
+       pop de
+       jr nz, @no_new_frame REL
+       
+               ; if new frame: clear timer
+               xor a, a
+               ld [hl], a ; clear timer
+               
+               inc bc ; bc = next animation ptr
+               ; load next table
+               ld hl, act_anim_table
+               add hl, de
+               ld a, [bc]
+               ld [hl+], a
+               inc bc
+               ld a, [bc]
+               ld [hl], a
 @no_new_frame:
   ret
 
index 70e2e86079fbbf240086303de5b2f84f64792112..ae461307bbf2ed88b0cb1e646ce54a4d4d7446c3 100644 (file)
        ; state switching may change this value.
 .de act_rt_timer, 1
        
+       ; animation frame timer
+.de act_rt_anim_timer, 1
+       
   ; stats1
 .de act_level, 1
 .de act_hp, stat_size
 .de action_st_action_ptr, 2
 .de action_size, 0 
 
+       ; animation header
+.se 0
+.de anim_header_frame_time, 1
+.de anim_header_next, 2
+
 ; animation entry struct
-; an animation table is *always* 
-; 3 entries followed by a next ptr
+; start with a header
+; an animation table *always* has
+; 3 entries 
 ; if the tile is 0x00 the entry is not rendered
 .se 0
 .de anim_ent_y_offset, 1
index f446c0e29131c7553b9a0246a7c7f0ba6f2fc76b..78703064b61a0ec8ff297adc2d008edfa3daa5a5 100644 (file)
        
        ; rt timer
        .db 0
+       ; rt animation timer
+       .db 0
 #endmacro
   
   ; defines an actor's stats (1/2)
        sub a, c
        ld b, a
 #endmacro
+       
+       ; animation header
+       ; inputs:
+       ;               $1: frame time
+       ;               $2: next frame ptr
+#macro anim_header
+       .db $1
+       dw $2
+#endmacro
 
        ; animation entry
        ; inputs:
index 1af0db1d4461d653ee417ca97e1f1105077926cd..653a73416d182db364ff5bbcdab1f0d116c1e0c0 100644 (file)
@@ -1,20 +1,20 @@
 unit_demo_guard_anim_table:
+       anim_header 0, unit_demo_guard_anim_table
        anim_ent 0, 0, 0x88, 0
        anim_ent 0, 8, 0x8A, 0
        anim_ent 0, 0, 0x00, 0
-       dw unit_demo_guard_anim_table
 
 unit_demo_dog_anim_table:
+       anim_header 0, unit_demo_dog_anim_table
        anim_ent 0, 0, 0x90, 0
        anim_ent 0, 8, 0x92, 0
        anim_ent 0, 0, 0x00, 0
-       dw unit_demo_dog_anim_table
 
 unit_demo_hazmat_anim_table:
+       anim_header 0, unit_demo_hazmat_anim_table
        anim_ent 0, 0, 0x94, 0
        anim_ent 0, 8, 0x96, 0
        anim_ent 0, 0, 0x00, 0
-       dw unit_demo_hazmat_anim_table
 
 unit_demo_1_init:
   ldnull bc