From: Lukas Krickl Date: Wed, 27 Aug 2025 15:16:38 +0000 (+0200) Subject: unit: units now attack X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=95c09c963937683a38c41bf41fa92be9625aae07;p=gbrg%2F.git unit: units now attack This does not work well yet. Only one unit should be able to attack. The attack direction is broken. --- diff --git a/src/action.s b/src/action.s index b9785a5..a824fa2 100644 --- a/src/action.s +++ b/src/action.s @@ -250,6 +250,7 @@ unit_action_attack_damage_calc: ld hl, STR_MISS ld de, UI_STATUS_LINE call puts + call ui_redraw_hp call ui_request_redraw ldnull bc ret diff --git a/src/unit_cpu.s b/src/unit_cpu.s index 80f2785..32b3556 100644 --- a/src/unit_cpu.s +++ b/src/unit_cpu.s @@ -50,7 +50,7 @@ unit_handle_cpu_inputs: ; and jump to move made if attack was performed call unit_cpu_attack_player cp a, 0 - jp nz, @move_made + jp nz, @attack_started ; clear move made buffer xor a, a @@ -132,6 +132,9 @@ unit_handle_cpu_inputs: @move_made: ld bc, st_unit_delay_to_active ret +@attack_started: + ld bc, st_action_attack_direction_picked + ret #undefine MOVE_MADE @@ -152,6 +155,10 @@ unit_cpu_attack_player: ld hl, player_unit+act_pos_y ld a, [hl] ; a = player y + + ; hl = rt action dat 1 + ld hl, act_rt_action_dat1 + add hl, de ; check y distance call distance @@ -171,18 +178,27 @@ unit_cpu_attack_player: ret @attack_up: + ; write direction values + ld a, DIRUP + ld [hl], a ld a, 1 ; attack ret @attack_down: + ld a, DIRDOWN + ld [hl], a ld a, 1 ; attack ret @attack_left: + ld a, DIRLEFT + ld [hl], a ld a, 1 ; attack ret @attack_right: + ld a, DIRRIGHT + ld [hl], a ld a, 1 ; attack ret