From eab2d556e2499f2c7ec9a68e9c8eb79e57cf6f1c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 17 Aug 2025 17:51:17 +0200 Subject: [PATCH] attack: wip added attack animation The location is still wrong but the basic idea is there :^) --- src/action.s | 74 +++++++++++++++++++++++++++++++++++++++++----- src/defs.s | 3 +- src/macros.inc | 4 +-- tiles/bank8800.inc | 24 +++++++-------- 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/src/action.s b/src/action.s index 4ac3b49..3b77df7 100644 --- a/src/action.s +++ b/src/action.s @@ -1,4 +1,6 @@ - +#define ACTION_ATTACK_SPRITE1 0xA0 +#define UNIT_ACTION_ATTACK_ANIM_LEN 16 + ; sets up default actions for a new game ; for button A and button B actions_new_game_init: @@ -68,9 +70,10 @@ unit_action_attack_pick_direction: ; bc: null if no press ; bc: unit_switch_to_active -> B pressed ; bc: bc input -> direction pressed - ; act_rt_action_tmp: writes pressed bit BTNUP, BTNDOWN, BTNLEFT, BTNRIGHT + ; act_rt_action_dat1: writes pressed bit BTNUP, BTNDOWN, BTNLEFT, BTNRIGHT + ; act_rt_action_dat2: set to 0 unit_action_pick_direction: - ld hl, act_rt_action_tmp + ld hl, act_rt_action_dat1 add hl, de ; hl = act_rt_action ; save next state @@ -107,20 +110,77 @@ unit_action_pick_direction: ret @direction_pressed: ld a, b - ld [hl], a ; write pressed button to action tmp + ld [hl+], a ; write pressed button to action dat + xor a, a + ; clear dat2 + ld [hl], a + + call ui_status_line_clear + ; should contain next state pop bc ret - ; performs an attack ; based on the units rt_action tmp value ; inputs: ; de: unit ; returns: ; bc: next action -unit_action_attack: - call ui_status_line_clear +unit_action_attack: + push de + ; get location + call unit_get_pos + + ld de, act_rt_action_dat1 + add hl, de + ; TODO determine where to draw animation + ld a, [hl] ; a = direction pressed + + ; 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 + + + ; check anim length + pop de + ld hl, act_rt_action_dat2 ; dat2 = animation frame count + add hl, de + ld a, [hl] + inc a + ld [hl], a + 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: + ; set animation timer and delay ld bc, st_unit_delay_to_active_template ret diff --git a/src/defs.s b/src/defs.s index bf8d2d6..a378c30 100644 --- a/src/defs.s +++ b/src/defs.s @@ -180,7 +180,8 @@ ; set during unit_collision_woth_any_other .de act_rt_collided_with, 2 ; temporary buffer for any action picked -.de act_rt_action_tmp, 1 +.de act_rt_action_dat1, 1 +.de act_rt_action_dat2, 1 ; sub-tile drawing vars ; during this animation the actor is already technically in its new diff --git a/src/macros.inc b/src/macros.inc index 6952a31..808b29c 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -190,8 +190,8 @@ .db 0 ; act_rt_sub_tile ; act_rt_loot_table_dat dw 0 - ; act_rt_action_tmp - .db 0 + ; act_rt_action_dat1/2 + .db 0, 0 #endmacro ; defines an actor's stats (1/2) diff --git a/tiles/bank8800.inc b/tiles/bank8800.inc index cf2b3b1..6c6010b 100644 --- a/tiles/bank8800.inc +++ b/tiles/bank8800.inc @@ -273,18 +273,18 @@ ; tile 16 .chr 00000000 .chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 -.chr 00000000 +.chr 00300000 +.chr 03130000 +.chr 03213000 +.chr 00313000 +.chr 00321300 +.chr 00031300 +.chr 00032130 +.chr 00003130 +.chr 00003213 +.chr 00000313 +.chr 00000323 +.chr 00000030 .chr 00000000 .chr 00000000 ; tile 17 -- 2.30.2