actions: Added setup for picking directions
authorLukas Krickl <lukas@krickl.dev>
Sun, 17 Aug 2025 04:09:15 +0000 (06:09 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 17 Aug 2025 04:09:15 +0000 (06:09 +0200)
src/action.s
src/defs.s
src/macros.inc

index eeb6ded9fcbc7059b0fbe542c9bdc1127155bcde..c16c81d4da83b82f7b2f66512f7d2110e7c90b22 100644 (file)
@@ -55,16 +55,78 @@ unit_action_attack_pick_direction_init:
        ;       returns:
        ;               bc: next action
 unit_action_attack_pick_direction:
+       ld bc, st_action_attack_direction_picked
+       jp unit_action_pick_direction
+       
+       ; generic direction picker
+       ; press B to abort
+       ;       press keyopad to pick direction
+       ;       inputs:
+       ;               de: unit
+       ;               bc: next success state
+       ;       returns:
+       ;               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
+unit_action_pick_direction:
+       ld hl, act_rt_action_tmp
+       add hl, de ; hl = act_rt_action
+       
+       ; save next state
+       push bc
+       
        ; b to abort
        ld b, BTNB
        input_just
+       pop bc ; need to pop in case of jp
        jp nz, unit_switch_to_active
 
+       push bc ; save again..
+
+
+       ld b, BTNUP
+       input_just
+       jr nz, @direction_pressed REL
+
+       ld b, BTNDOWN
+       input_just
+       jr nz, @direction_pressed REL
+
+       ld b, BTNLEFT
+       input_just
+       jr nz, @direction_pressed REL
+
+       ld b, BTNRIGHT
+       input_just
+       jr nz, @direction_pressed REL
+       
+       pop bc ; remove from stack
+       
        ldnull bc
        ret
+@direction_pressed:
+       ld a, b
+       ld [hl], a ; write pressed button to action tmp
+       ; 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:
+       jp unit_switch_to_active
+       ret
 
        ; default attack state
 st_action_attack_init:
        st_def 0x00, unit_action_attack_pick_direction_init, st_action_attack_pick_direction 
 st_action_attack_pick_direction:
        st_def 0x00, unit_action_attack_pick_direction, st_action_attack_pick_direction
+st_action_attack_direction_picked:
+       st_def 0x00, unit_action_attack, st_action_attack_direction_picked
index 6ea6df3c86d292575eefcbd76989d01f20a3d83c..723d9e7f712679892c3cf39c5a8b2cc171b26a9f 100644 (file)
   ; last collision with actor
   ; 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
 
   ; sub-tile drawing vars
   ; during this animation the actor is already technically in its new 
 
 #define DISTANCE_BGTA 1
 #define DISTANCE_AGTB 0
+
index 903578ec117eca6b9b5245ec0121f7fdf425b32c..6952a31a9da23b53fb57ce91f5f467469513fefb 100644 (file)
   .db 0  ; act_rt_sub_tile 
   ; act_rt_loot_table_dat
   dw 0
+       ; act_rt_action_tmp
+       .db 0
 #endmacro
   
   ; defines an actor's stats (1/2)