From fde591defb28f98791aca5261b3d6e8d5b8c219a Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 6 Oct 2024 09:49:29 +0200 Subject: [PATCH] Added basic drawing rotuine for stat bars --- src/ui.s | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/ui.s b/src/ui.s index 2f898a4..efa3bb2 100644 --- a/src/ui.s +++ b/src/ui.s @@ -7,6 +7,8 @@ #define THP_BAR_SINGLE_EMPTY 0x3E #define THP_BAR_SINGLE_FULL 0x3D + ; difference between start and empty bar +#define THP_BAR_EMPTY_DIFF 4 ; sets up static parts of the UI ; all other parts are drawin by ui_draw @@ -56,6 +58,30 @@ ui_draw_bar_single: ld [hl+], a ret + ; decides if a bar should be empty or filled + ; inputs: + ; b: current + ; c: max + ; a: filled tile + ; e: total drawn + ; hl: destination ptr + ; returns: hl + 1; e++ +ui_draw_bar_empty_or_filled: + ld [itmp], a + ld a, b ; a = current + cp a, e + ld a, [itmp] ; a = tile + ; if total drwan > a + ; switch to empty tile + jp z, @equal + jp nc, @not_empty +@equal: + add a, THP_BAR_EMPTY_DIFF ; move to empty +@not_empty: + ld [hl+], a + inc e + ret + ; draws a UI bar ; the bar will be filled up to hp/mp ; al others will be empty @@ -79,13 +105,33 @@ ui_draw_bar: ; and b = current ld c, a - ; first we draw the filled bar + ld e, 0 ; e = total drawn + + ; draw left most bar tile ld a, THP_BAR_START - ld [hl+], a - inc a - ld [hl+], a - inc a - ld [hl+], a + call ui_draw_bar_empty_or_filled + + ld a, c ; a = max. guaranteed not 0 or 1 here! + sub a, 2 ; max - 2 (left and righr-most tile) + ld d, a ; d = loop counter + cp a, 0 ; if loop count is 0 skip + jr z, @skip REL + +@loop: + ld a, THP_BAR_START+1 + call ui_draw_bar_empty_or_filled + + ; d-- + dec d + ld a, d + cp a, 0 + ; while not 0 + jp nz, @loop +@skip: + + ; left-most tile + ld a, THP_BAR_START+2 + call ui_draw_bar_empty_or_filled ret ; sets up for drawing hp bar -- 2.30.2