attack: reduced attack animation to 1 frame for now
authorLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:37:46 +0000 (17:37 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 27 Aug 2025 15:37:46 +0000 (17:37 +0200)
hp UI is not redrawing but hits are registered

src/action.s
src/unit_cpu.s

index a824fa225ade912451ffdc74480cdfae55229320..56ca42f8bca6c8e460a435464b0111be6aa15726 100644 (file)
@@ -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
index 32b35567820161aa0db1daa994f0e39f816f03c3..a3bb9e6818c260370cafbbca16ac3965f4d432fb 100644 (file)
@@ -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: