WIP: ui drawing code for hp/mp
authorLukas Krickl <lukas@krickl.dev>
Fri, 4 Oct 2024 15:22:57 +0000 (17:22 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 4 Oct 2024 15:22:57 +0000 (17:22 +0200)
src/ui.s
src/video.s
src/wram.s

index 4a36d2d23c8c9eb98701f76a3bf8adb3bf6f8487..00c4030726001eff4f29ea658c28a61ca108667e 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -1,10 +1,10 @@
 #define THP_ICON 0x33
 #define TMP_ICON 0x37
 
-  ; update the UI 
-  ; this should only be called 
-  ; during blanking 
-ui_draw:
+  ; sets up static parts of the UI
+  ; all other parts are drawin by ui_draw
+  ; only call during blanking
+ui_init:
   ; draw hp string
   ld hl, STR_HP
   ld de, SCRN0_UI
@@ -14,10 +14,21 @@ ui_draw:
   ld hl, STR_MP
   ld de, SCRN0_UI+10
   call puts
+
+  ; darw mp and hp on first frame 
+  ld a, UI_REDRAW_HP | UI_REDRAW_MP 
+  ld [ui_flags], a
+
+  ret
+
+  ; draws a UI bar 
+  ; inputs:
+  ;   hl: screen location
+  ;   [de]: amount of bars to draw
+ui_draw_bar:
   
-  ; draw hp UI
+
   ld a, THP_ICON
-  ld hl, SCRN0_UI+SCRN_W
   ld [hl+], a
   inc a
   ld [hl+], a
@@ -25,6 +36,29 @@ ui_draw:
   ld [hl+], a
   inc a
   ld [hl+], a
+  ret
+
+  ; update the UI 
+  ; this should only be called 
+  ; during blanking 
+ui_draw:
+  ; check if we should darw hp bar
+  ld a, [ui_flags]
+  cp a, 0
+  jr z, @skip REL
+
+  ; draw hp UI
+  ld hl, SCRN0_UI+SCRN_W
+  ; player hp ptr
+  ld de, player + player_hp
+  ; check redraw hp flag
+  and a, UI_REDRAW_HP 
+  call nz, ui_draw_bar
+
+  ; check if we should draw mp bar
+  ld a, [ui_flags]
+  and a, UI_REDRAW_HP 
+  jr z, @no_mp_draw REL
   
   ; draw mp UI 
   ld a, TMP_ICON
@@ -38,5 +72,10 @@ ui_draw:
   ld [hl+], a
   inc a
   ld [hl+], a
+@no_mp_draw:
 
+  ; set flags to 0 
+  xor a, a
+  ld [ui_flags], a
+@skip:
   ret
index e31532188c3d11cdf3c1cc13b9b3448d920b3c3f..92a6f47af4298580e53d304c551fb016ec702576 100644 (file)
@@ -64,6 +64,8 @@ video_init:
 
   ld a, 0b11011000
   ld [ROBP1], a
+  
+  call ui_init
 
   ret
 
index acae72c4274c23a7e668be9d7c6a37bd7b9cf9c2..19895956757535065eab6f4ff902df67bd68d5d8 100644 (file)
@@ -69,3 +69,13 @@ player: .adv player_size
 
   ; pointer to current room struct 
 curr_room: .adv 2
+
+  ; drawing related flags
+
+  ; UI flags 
+.se 1
+.de UI_REDRAW_HP, 1
+.de UI_REDRAW_MP, 2
+
+ui_flags: .adv 1
+draw_flags: .adv 1