animations: Added animation loading based on tables
authorLukas Krickl <lukas@krickl.dev>
Sat, 13 Sep 2025 05:03:29 +0000 (07:03 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 13 Sep 2025 05:03:29 +0000 (07:03 +0200)
This replaced the old hard-coded animations for attacks.

src/action.s
src/animation.s
src/attack.s

index 3a2fc10e79c6fe63f92405205c2a794e483d2818..9c55d2ad31dac7ffb805b80b9e3ff4fa825963fe 100644 (file)
@@ -95,7 +95,8 @@ unit_action_pick_direction:
        ; should contain next state
        pop bc
        ret
-       
+
+
        ; get the attack location
        ; input:
        ;               de: actor
index 71fccb8f7d462455f92734e843875bd4a7df3995..d90224a9366923392ad67d42f30f1cb758036c26 100644 (file)
@@ -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
index a5a03c8a4a20549e7831d61772dc42c73c513ce3..8dd23ad535e757b59c9ad325706dea4be73b4a89 100644 (file)
@@ -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]