From: Lukas Krickl Date: Wed, 27 Aug 2025 15:37:46 +0000 (+0200) Subject: attack: reduced attack animation to 1 frame for now X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=3b8f5b1711da1ee4a32203d1dc6ad2846265f836;p=gbrg%2F.git attack: reduced attack animation to 1 frame for now hp UI is not redrawing but hits are registered --- diff --git a/src/action.s b/src/action.s index a824fa2..56ca42f 100644 --- a/src/action.s +++ b/src/action.s @@ -1,5 +1,5 @@ #define ACTION_ATTACK_SPRITE1 0xA0 -#define UNIT_ACTION_ATTACK_ANIM_LEN 16 +#define UNIT_ACTION_ATTACK_ANIM_LEN 1 ; sets up default actions for a new game ; for button A and button B @@ -57,7 +57,7 @@ unit_action_attack_pick_direction_init: ; returns: ; bc: next action unit_action_attack_pick_direction: - ld bc, st_action_attack_direction_picked + ld bc, st_action_attack_damage_actor jp unit_action_pick_direction ; generic direction picker @@ -212,7 +212,7 @@ unit_action_attack: @done: ; set animation timer and delay - ld bc, st_action_attack_damage_actor + ld bc, st_unit_delay_to_active ret ; performs damage calculations based on the attacked location @@ -264,4 +264,4 @@ st_action_attack_pick_direction: st_action_attack_direction_picked: st_def 0x00, unit_action_attack, st_action_attack_direction_picked st_action_attack_damage_actor: - st_def 0x00, unit_action_attack_damage_calc, st_unit_delay_to_active_template + st_def 0x00, unit_action_attack_damage_calc, st_action_attack_direction_picked diff --git a/src/unit_cpu.s b/src/unit_cpu.s index 32b3556..a3bb9e6 100644 --- a/src/unit_cpu.s +++ b/src/unit_cpu.s @@ -133,7 +133,7 @@ unit_handle_cpu_inputs: ld bc, st_unit_delay_to_active ret @attack_started: - ld bc, st_action_attack_direction_picked + ld bc, st_action_attack_damage_actor ret #undefine MOVE_MADE @@ -147,6 +147,19 @@ unit_handle_cpu_inputs: ; a: 1 attack performed ; a: 0 no attack unit_cpu_attack_player: + ; first check if x == x player + ld hl, act_pos_x + add hl, de + ld a, [hl] + ld b, a ; b = act x + + ld hl, player_unit+act_pos_x + ld a, [hl] + + ; they need to be equal to be in range + cp a, b + jr nz, @not_in_y_range REL + ld hl, act_pos_y add hl, de @@ -167,7 +180,7 @@ unit_cpu_attack_player: ld a, c ; find out which direction cp a, DISTANCE_AGTB ; jump up or down - jp z, @attack_up + jp nz, @attack_up jp @attack_down @not_in_y_range: