unit: units now attack
authorLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:16:38 +0000 (17:16 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:16:38 +0000 (17:16 +0200)
This does not work well yet. Only one unit should be able to attack.
The attack direction is broken.

src/action.s
src/unit_cpu.s

index b9785a5219e77d56e5e9b6b93e3f8cbaa1c64d7c..a824fa225ade912451ffdc74480cdfae55229320 100644 (file)
@@ -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
index 80f2785bc7b5718c72592d000c46c60f646f6d7a..32b35567820161aa0db1daa994f0e39f816f03c3 100644 (file)
@@ -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