unit: Added ui redraw when using moves
authorLukas Krickl <lukas@krickl.dev>
Wed, 14 May 2025 16:34:08 +0000 (18:34 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 14 May 2025 16:34:08 +0000 (18:34 +0200)
src/ui.s
src/unit.s

index 71474ed2dd213aaba9ee5418754e93af24165992..5b5f521319df511a5e8afc8eeeaf07411b354d24 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -45,14 +45,21 @@ ui_draw:
   sub a, d ; max - current
   ld e, a ; e = moves max counter
 
+  ld hl, SCRN1+1
+
   ; draw to screen
+  ld a, d
+  cp a, 0
+  jr z, @skip_loop_current REL
+
   ld a, UI_TILE_MOVE
-  ld hl, SCRN1+1 
 @loop_current:
     ld [hl+], a
     dec d
   jr nz, @loop_current REL
 
+@skip_loop_current:
+
   ; draw used moves 
   ld a, e ; check if e is already 0
   cp a, 0
index 8a6f664a1bfe25faa11114754c81573dc11b09af..795b4157546b315c41e19bdf554b70c55f11decf 100644 (file)
@@ -174,6 +174,9 @@ unit_handle_inputs:
   ;   actor initiative based on tile flags
   ;   actor position
 unit_try_move_up:
+  call unit_use_move
+  ret z
+
   ld hl, act_pos_y
   add hl, de
   ; hl = actor y
@@ -187,6 +190,9 @@ unit_try_move_up:
   ret
 
 unit_try_move_down:
+  call unit_use_move
+  ret z
+
   ld hl, act_pos_y
   add hl, de
   ; hl = actor y
@@ -199,6 +205,9 @@ unit_try_move_down:
   ret
 
 unit_try_move_left:
+  call unit_use_move
+  ret z
+
   ld hl, act_pos_x
   add hl, de
   ; hl = actor x
@@ -211,6 +220,9 @@ unit_try_move_left:
   ret
 
 unit_try_move_right:
+  call unit_use_move
+  ret z
+
   ld hl, act_pos_x
   add hl, de
   ; hl = actor x
@@ -221,6 +233,26 @@ unit_try_move_right:
   inc a
   ld [hl], a
   ret
+  
+  ; consumes a move
+  ; sets UI redraw flag
+  ; fails (z flag set) if no moves left
+  ; inputs:
+  ;   de: unit
+unit_use_move:
+  push de
+  
+  ld hl, act_moves
+  add hl, de
+  pop de ; hl = act_moves
+
+  ld a, [hl] ; current
+  cp a, 0
+  ret z
+  dec a
+  ld [hl], a
+  call ui_unit_need_draw
+  ret
 
   ; centers the current scroll on the selected unit
   ; snaps to corners of the map