From 0df6d25ff008448e997d2b4000689be863536464 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Wed, 14 May 2025 18:34:08 +0200 Subject: [PATCH] unit: Added ui redraw when using moves --- src/ui.s | 9 ++++++++- src/unit.s | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ui.s b/src/ui.s index 71474ed..5b5f521 100644 --- 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 diff --git a/src/unit.s b/src/unit.s index 8a6f664..795b415 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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 -- 2.30.2