unit: fixed movement delya being too long
authorLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 05:32:37 +0000 (07:32 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 13 Jul 2025 05:32:37 +0000 (07:32 +0200)
This was caused by the delay timer only being set *after* collision
check.
This caused the delay to be the last unit's delay which may be slower or
faster than expected.

BUGS.md
src/unit.s

diff --git a/BUGS.md b/BUGS.md
index 9843a446a07719a6e8bcc59e081f8e005952faa1..97fed4bb3c2cd7208d7f622b85bf5a07b4f4123b 100644 (file)
--- a/BUGS.md
+++ b/BUGS.md
@@ -1,10 +1,2 @@
 # Known Bugs
 
-## Objects are out of bounds
-
-Sometimes objects are flickering at tile 0/0.
-
-## When hitting an actor the delay timer is too long
-
-When the player runs into an actor the movement delay triggeered
-is way longer than expected.
index 10b75d9567a58d722fa7fcccaafac65a9ba85626..3836ed7580931b2122c774517af2bd85bedea1dc 100644 (file)
@@ -478,6 +478,12 @@ unit_set_delay_to_active_speed:
   ;   actor initiative based on tile flags
   ;   actor position
 unit_try_move_up:
+  ; enable subtile up
+  ld a, 0b10100000
+  push de
+  call unit_set_delay_to_active_speed
+  pop de
+
   ; y - 1
   unit_test_collision dec b, CF_COLLISION
 
@@ -494,13 +500,16 @@ unit_try_move_up:
   dec a 
   ld [hl], a
   
-  ; enable subtile up
-  ld a, 0b10100000
-  call unit_set_delay_to_active_speed
 
   ret
 
 unit_try_move_down:
+  ; enable subtile down
+  push de
+  ld a, 0b01100000
+  call unit_set_delay_to_active_speed
+  pop de
+
   ; y + 1
   unit_test_collision inc b, CF_COLLISION
 
@@ -513,14 +522,16 @@ unit_try_move_down:
   
   inc a
   ld [hl], a
-
-  ; enable subtile down
-  ld a, 0b01100000
-  call unit_set_delay_to_active_speed
   
   ret
 
 unit_try_move_left:
+  ; enable subtile left
+  push de
+  ld a, 0b00110000
+  call unit_set_delay_to_active_speed
+  pop de
+
   ; x - 1
   unit_test_collision dec c, CF_COLLISION
 
@@ -533,15 +544,16 @@ unit_try_move_left:
   
   dec a
   ld [hl], a
-  ; enable subtile left
-  ld a, 0b00110000
-  call unit_set_delay_to_active_speed
   
   ret
 
 unit_try_move_right:
-  
+  ; enable subtile right
+  push de
+  ld a, 0b00101000
+  call unit_set_delay_to_active_speed
+  pop de
+
   ; x + 1
   unit_test_collision inc c, CF_COLLISION
 
@@ -555,10 +567,6 @@ unit_try_move_right:
   inc a
   ld [hl], a
 
-  ; enable subtile right
-  ld a, 0b00101000
-  call unit_set_delay_to_active_speed
-
   ret