From e7a4bc49c203b876ff09ab3cc6ec2764575b9c2c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 17 Aug 2025 06:09:15 +0200 Subject: [PATCH] actions: Added setup for picking directions --- src/action.s | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/defs.s | 3 +++ src/macros.inc | 2 ++ 3 files changed, 67 insertions(+) diff --git a/src/action.s b/src/action.s index eeb6ded..c16c81d 100644 --- a/src/action.s +++ b/src/action.s @@ -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 diff --git a/src/defs.s b/src/defs.s index 6ea6df3..723d9e7 100644 --- a/src/defs.s +++ b/src/defs.s @@ -179,6 +179,8 @@ ; 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 @@ -362,3 +364,4 @@ #define DISTANCE_BGTA 1 #define DISTANCE_AGTB 0 + diff --git a/src/macros.inc b/src/macros.inc index 903578e..6952a31 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -190,6 +190,8 @@ .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) -- 2.30.2