unit: made unit switching more user friendly
authorLukas Krickl <lukas@krickl.dev>
Tue, 20 May 2025 16:32:01 +0000 (18:32 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 20 May 2025 16:32:01 +0000 (18:32 +0200)
This change simply delays the switch for a few frames

src/unit.s
src/wram.s

index 3d6cdb295192ecce7d3c2bce6dcd68f8e362c675..e6e4953ace80d4999ec2873e8dd274f0e24fd30a 100644 (file)
@@ -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:
index 9ccd82f42193151e09f106e105387c6a7ad7af8a..f598058c99fd8b393ecfb71f642a48cf153bbbf9 100644 (file)
@@ -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