#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
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
; 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