From: Lukas Krickl Date: Tue, 20 May 2025 16:32:01 +0000 (+0200) Subject: unit: made unit switching more user friendly X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5f66927ea3105cfc308af007c5e113223bf8394e;p=gbrg%2F.git unit: made unit switching more user friendly This change simply delays the switch for a few frames --- diff --git a/src/unit.s b/src/unit.s index 3d6cdb2..e6e4953 100644 --- a/src/unit.s +++ b/src/unit.s @@ -137,7 +137,7 @@ unit_handle_inputs: jr z, @notup REL call unit_try_move_up - ld bc, st_unit_delay + ld bc, st_unit_delay_to_active ret @notup: @@ -145,7 +145,7 @@ unit_handle_inputs: jr z, @notdown REL call unit_try_move_down - ld bc, st_unit_delay + ld bc, st_unit_delay_to_active ret @notdown: @@ -153,7 +153,7 @@ unit_handle_inputs: jr z, @notleft REL call unit_try_move_left - ld bc, st_unit_delay + ld bc, st_unit_delay_to_active ret @notleft: @@ -161,7 +161,7 @@ unit_handle_inputs: jr z, @notright REL call unit_try_move_right - ld bc, st_unit_delay + ld bc, st_unit_delay_to_active ret @notright: @@ -254,11 +254,12 @@ unit_use_move: pop de ; hl = act_moves ld a, [hl] ; current - cp a, 0 - + cp a, 1 ; if 1 request next + push_all call z, unit_next_request pop_all + cp a, 0 ; if 0 exit ret z dec a @@ -384,6 +385,10 @@ unit_next_request: ld [gameplay_unit_current], a ld a, d ld [gameplay_unit_current+1], a + + ; set up delay timer + ld a, 16 + ld [unit_next_timer], a ret @@ -397,6 +402,15 @@ unit_next_request: ; uses: ; unit_next_best_init: as a temporary buffer unit_next: + ; if the unit_next timer is not 8 + ; wait and timer-- + ld a, [unit_next_timer] + cp a, 0 + jr z, @go REL + dec a + ld [unit_next_timer], a + ret +@go: ; unset flag ld a, [gameplay_flags] xor a, GPF_UNIT_NEXT @@ -553,7 +567,7 @@ st_unit_demo_1_update: st_unit_demo_1_idle: st_def 0x00, unit_demo_1_idle, st_unit_demo_1_idle -st_unit_delay: +st_unit_delay_to_active: st_def CURSOR_MOVE_TIMER, st_null_fn, st_unit_switch_to_active st_unit_switch_to_active: diff --git a/src/wram.s b/src/wram.s index 9ccd82f..f598058 100644 --- a/src/wram.s +++ b/src/wram.s @@ -19,6 +19,7 @@ game_mode: .adv st_size ; current best init found in units_next unit_next_best_init: .adv 1 unit_next_best_act_ptr: .adv 2 +unit_next_timer: .adv 1 ; actors ; actors are state machines