Added basic drawing rotuine for stat bars
authorLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 07:49:29 +0000 (09:49 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 6 Oct 2024 07:49:29 +0000 (09:49 +0200)
src/ui.s

index 2f898a4a87a4b4451b561b3715c17affc45ef11e..efa3bb25d275b1d2f500376c304857615c0cc82a 100644 (file)
--- 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