ui: Added basic ui element for remaining moves
authorLukas Krickl <lukas@krickl.dev>
Tue, 13 May 2025 18:09:40 +0000 (20:09 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 13 May 2025 18:09:40 +0000 (20:09 +0200)
src/defs.s
src/ui.s
src/unit.s
src/update.s
src/wram.s

index 9a7eba9b02ebcf42a96f6133d3d3696871c8dd38..50d90106643cbfb9c48e9f51fd3cad96b791e7e2 100644 (file)
 #define CURSOR_MIN_Y 0 
 #define CURSOR_MAX_Y 0xB8
 
+  ; draw flags
+.se 1
+.de DRAWF_UPDATE_UI, 1
+
   ; cell flags
-.se 0 
+.se 1 
 .de CF_COLLISION, 1
 
   ; cells struct
index ab6b7e116e5f1176ae135de5c75cb95e16af6e46..872ce05ad1983e641ce8f4b2803979f124c6433e 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -4,11 +4,49 @@
 
   ; inits UI
 ui_init:
-  call ui_draw
+  ret
+
+  ; schedules a unit draw
+  ; inputs:
+  ;   de: unit
+ui_unit_need_draw:
+  ld a, [draw_flags]
+  or a, DRAWF_UPDATE_UI
+  ld [draw_flags], a
+  
+  ; store actor 
+  ld hl, ui_draw_actor
+  ld a, e
+  ld [hl+], a
+  ld a, d
+  ld [hl], a
+
   ret
 
   ; update the UI 
   ; this should only be called 
   ; during blanking 
 ui_draw:
+  ld a, [draw_flags]
+  xor a, DRAWF_UPDATE_UI
+  ld [draw_flags], a
+  
+  ld a, [ui_draw_actor]
+  ld l, a
+  ld a, [ui_draw_actor+1]
+  ld h, a
+  ; hl = actor 
+  ld de, act_moves
+  add hl, de ; hl = current moves
+  ld a, [hl] ; a = counter
+  ld d, a ; d = counter
+  
+  ; draw to screen
+  ld a, UI_TILE_MOVE
+  ld hl, SCRN1+1 
+@loop:
+    ld [hl+], a
+    dec d
+  jr nz, @loop REL
+
   ret
index d4cb1959020608628f3a0bea6719daf7031a66c3..8a6f664a1bfe25faa11114754c81573dc11b09af 100644 (file)
@@ -42,6 +42,7 @@ units_update:
   ret
 
 unit_demo_1_init:
+  call ui_unit_need_draw
   ldnull bc
   ret
   
@@ -252,7 +253,6 @@ unit_scroll_center:
   ; x position scroll
   ld a, [hl]
 
-  BREAK
   ; max x
   cp a, 0x16
   jr c, @not_max_x REL
@@ -307,7 +307,7 @@ unit_next:
 
 unit_demo_1:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_update
-  act_def ACT_T_DEMO_1, 0, 1, 1, 1, 1, 1, 2, 2, 0 
+  act_def ACT_T_DEMO_1, 0, 1, 2, 3, 4, 5, 2, 2, 0 
   act_st_def NULL, NULL, st_unit_demo_1_update, NULL
   
 st_unit_demo_1_update:
index 1edf380906b9c3f8002fcb7a87ba1f3a07a5ef65..95c051c00bcb61b4211ba91979aca6f611f1e16a 100644 (file)
@@ -5,6 +5,10 @@ update_game:
   ; tick rng every frame
   call rand
   call rand_save_srand
+  
+  ld a, [draw_flags]
+  and a, DRAWF_UPDATE_UI
+  call nz, ui_draw
 
   ld hl, p0_units
   call units_update
index 1fbe1b958b77643bf12947de0fad38e9a132d089..77cc0e1e1d8b3ff5fdd2405357f1e3aca1512a87 100644 (file)
@@ -27,6 +27,11 @@ actor_player: .adv act_size
 bg_update_index: .adv 2
 bg_update_queue: .adv bge_size * BGE_MAX 
 
+draw_flags: .adv 1
+
+  ; ptr to actor for next UI update
+ui_draw_actor: .adv 2
+
   ; game state
   ; this region holds the entire game state
   ; everything thats needed for a savme game should be