From 1e12aef9d360987fdf202a8b8c9cb9225f357e03 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 13 Sep 2025 07:03:29 +0200 Subject: [PATCH] animations: Added animation loading based on tables This replaced the old hard-coded animations for attacks. --- src/action.s | 3 +- src/animation.s | 105 +++++++++++++++++++++++++++++++++++++++++++++--- src/attack.s | 71 ++++++++++++++++++-------------- 3 files changed, 141 insertions(+), 38 deletions(-) diff --git a/src/action.s b/src/action.s index 3a2fc10..9c55d2a 100644 --- a/src/action.s +++ b/src/action.s @@ -95,7 +95,8 @@ unit_action_pick_direction: ; should contain next state pop bc ret - + + ; get the attack location ; input: ; de: actor diff --git a/src/animation.s b/src/animation.s index 71fccb8..d90224a 100644 --- a/src/animation.s +++ b/src/animation.s @@ -9,10 +9,35 @@ player_anim_table_f2: anim_ent 1, 8, 0x8C, OAM_FXFLIP anim_ent 1, 0, 0x8E, OAM_FXFLIP anim_ent 0, 0, 0x00, 0 + +player_anim_table_attack_up: + anim_header 32, player_anim_table + anim_ent 1, 8, 0x8C, OAM_FXFLIP + anim_ent 1, 0, 0x8E, OAM_FXFLIP + anim_ent -12, 0, ACTION_ATTACK_SPRITE1, 0 + +player_anim_table_attack_down: + anim_header 32, player_anim_table + anim_ent 1, 8, 0x8C, OAM_FXFLIP + anim_ent 1, 0, 0x8E, OAM_FXFLIP + anim_ent 12, 0, ACTION_ATTACK_SPRITE1, 0 + +player_anim_table_attack_left: + anim_header 32, player_anim_table + anim_ent 1, 8, 0x8C, OAM_FXFLIP + anim_ent 1, 0, 0x8E, OAM_FXFLIP + anim_ent 0, -12, ACTION_ATTACK_SPRITE1, 0 + +player_anim_table_attack_right: + anim_header 32, player_anim_table + anim_ent 1, 8, 0x8C, OAM_FXFLIP + anim_ent 1, 0, 0x8E, OAM_FXFLIP + anim_ent 0, 12, ACTION_ATTACK_SPRITE1, 0 ; table that maps actor type to ; a list of animations anim_actor_table: + dw NULL dw anim_list_player dw anim_list_guard dw anim_list_dog @@ -20,20 +45,52 @@ anim_actor_table: anim_list_player: - ; TDLE_NEUTRAL + ; IDLE_NEUTRAL dw player_anim_table ; ATTACK LEFT - dw player_anim_table + dw player_anim_table_attack_left ; ATTACK RIGHT - dw player_anim_table + dw player_anim_table_attack_right ; ATTACK_UP - dw player_anim_table + dw player_anim_table_attack_up ; ATTACK_DOWN - dw player_anim_table + dw player_anim_table_attack_down anim_list_guard: + ; IDLE NEUTRAL + dw unit_demo_guard_anim_table + ; ATTACK LEFT + dw unit_demo_guard_anim_table + ; ATTACK RIGHT + dw unit_demo_guard_anim_table + ; ATTACK UP + dw unit_demo_guard_anim_table + ; ATTACK DOWN + dw unit_demo_guard_anim_table + anim_list_dog: + ; idle neutral + dw unit_demo_dog_anim_table + ; attack left + dw unit_demo_dog_anim_table + ; attack right + dw unit_demo_dog_anim_table + ; attack up + dw unit_demo_dog_anim_table + ; attack down + dw unit_demo_dog_anim_table + anim_list_hazmat: + ; idle + dw unit_demo_hazmat_anim_table + ; attack left + dw unit_demo_hazmat_anim_table + ; attack right + dw unit_demo_hazmat_anim_table + ; attack up + dw unit_demo_hazmat_anim_table + ; attack down + dw unit_demo_hazmat_anim_table ; translates tile to screen @@ -56,12 +113,48 @@ anim_list_hazmat: ; writes: ; new animation into selected actor anim_load_type: - ; TODO: + push de ; save actor + ; 1) load animation list based on type + ld hl, act_type + add hl, de + ld a, [hl] ; a = actor type + sla a ; * 2 to use as ptr offset + ld d, 0 + ld e, a + ld hl, anim_actor_table + add hl, de + + ld a, [hl+] + ld d, a + ld a, [hl+] + ld h, a + ld l, d ; 2) load animation table based on requested animation + sla b ; * 2 to get offset + ld d, 0 + ld e, b + add hl, de ; get animation ptr + + ld a, [hl+] + ld c, a + ld a, [hl+] + ld b, a + + ; bc = animation ptr + ; 3) write animation to animation entry + pop de ; restore actor + + ; write anim table + ld hl, act_anim_table + add hl, de + ld a, c + ld [hl+], a + ld a, b + ld [hl], a ret ; performs no drawing diff --git a/src/attack.s b/src/attack.s index a5a03c8..8dd23ad 100644 --- a/src/attack.s +++ b/src/attack.s @@ -25,6 +25,43 @@ unit_action_attack_pick_direction_init: unit_action_attack_pick_direction: ld bc, st_action_attack_damage_actor jp unit_action_pick_direction + + ; decides which animation to load + ; based on units action dat 1 direction + ; inputs: + ; de: actor +unit_action_attack_decide_animation: + ld hl, act_rt_action_dat1 + add hl, de + + ld a, [hl] + cp a, DIRUP + jr nz, @notup REL + ld b, ANIM_T_ATTACK_UP + call anim_load_type + ret +@notup: + + cp a, DIRDOWN + jr nz, @notdown REL + ld b, ANIM_T_ATTACK_DOWN + call anim_load_type + ret +@notdown: + + cp a, DIRLEFT + jr nz, @notleft REL + ld b, ANIM_T_ATTACK_LEFT + call anim_load_type + ret +@notleft: + + cp a, DIRRIGHT + jr nz, @notright REL + ld b, ANIM_T_ATTACK_RIGHT + call anim_load_type +@notright: + ret ; performs an attack ; based on the units rt_action tmp value @@ -34,35 +71,10 @@ unit_action_attack_pick_direction: ; bc: next action unit_action_attack: push de + call unit_action_attack_decide_animation + pop de - call unit_attack_get_attack_tile - - - ; draw a slash animation at that location - push bc - call load_unit_obj - call load_scroll - push bc - pop de ; de = scroll - pop bc ; bc = pos - ; hl = obj - ; write position - ld a, b ; y position - tile_to_scrn OBJ_OFF_Y, d - ld [hl+], a ; y position - - ld a, c ; x position - tile_to_scrn OBJ_OFF_X, e - ld [hl+], a ; x position - - ; write tile - ld a, ACTION_ATTACK_SPRITE1 - ld [hl+], a - - ; clear flags - xor a, a - ld [hl], a - + push de ; check anim length pop de @@ -74,12 +86,9 @@ unit_action_attack: cp a, UNIT_ACTION_ATTACK_ANIM_LEN jr z, @done REL - ; TODO: on frame 0 perform attack action - ; otherwsie keep going ldnull bc ret - @done: ; unset flag ld a, [gpf_attack_ongoing] -- 2.30.2