From de3f69f975789c088c40b6a309f42e6814c0edb2 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 9 Sep 2025 05:28:56 +0200 Subject: [PATCH] animation: Added frame wait state --- TODO.md | 8 ++++++++ src/animation.s | 53 +++++++++++++++++++++++++++++++++++-------------- src/defs.s | 13 ++++++++++-- src/macros.inc | 11 ++++++++++ src/unit_demo.s | 6 +++--- 5 files changed, 71 insertions(+), 20 deletions(-) diff --git a/TODO.md b/TODO.md index 5a04dc3..03c6f49 100644 --- a/TODO.md +++ b/TODO.md @@ -146,3 +146,11 @@ [ ] 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 diff --git a/src/animation.s b/src/animation.s index 0af7074..879dfc7 100644 --- a/src/animation.s +++ b/src/animation.s @@ -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 diff --git a/src/defs.s b/src/defs.s index 70e2e86..ae46130 100644 --- a/src/defs.s +++ b/src/defs.s @@ -190,6 +190,9 @@ ; 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 @@ -317,9 +320,15 @@ .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 diff --git a/src/macros.inc b/src/macros.inc index f446c0e..7870306 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -188,6 +188,8 @@ ; rt timer .db 0 + ; rt animation timer + .db 0 #endmacro ; defines an actor's stats (1/2) @@ -275,6 +277,15 @@ 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: diff --git a/src/unit_demo.s b/src/unit_demo.s index 1af0db1..653a734 100644 --- a/src/unit_demo.s +++ b/src/unit_demo.s @@ -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 -- 2.30.2