unit: Added individual dice display to each unit
authorLukas Krickl <lukas@krickl.dev>
Sun, 8 Jun 2025 05:52:52 +0000 (07:52 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 8 Jun 2025 05:52:52 +0000 (07:52 +0200)
src/defs.s
src/rand.s
src/unit.s
src/update.s

index 236bc4ee6ad96ec10acc9e1d858528f752c7a62d..8f01034f211bf917d39ef1af5e9d6ebe4942f5e1 100644 (file)
 .de act_oam_flags, 1
 
   ; actor runtime values
+
+  ; dice display
+  ; if timer > 0 the default draw
+  ; call will draw a dice instead of the regular 
+  ; sprite
 .de act_rt_dd_d16, 1 ; dice display value
 .de act_rt_dd_timer, 1
 .de act_rt_dd_flags, 1
index e339bafd8a8e0f25f232b6eca001f654fbba2891..0305c4cebd598246d581a77f911b761a91b86d9e 100644 (file)
@@ -92,35 +92,6 @@ roll_d16:
   pop hl
   ret
 
-
-
-  ; draws the last d16 result 
-  ; at a tile position for n frames
-  ; inputs:
-  ;   b/c: y/x tile
-  ;     a: dice display flags/0
-  ;   d16: roll to display
-  ; preserves flags
-dice_display_set:
-  ; set flags
-  ld a, [dd_flags]
-
-  ; set timer
-  ld a, DD_TIME
-  ld [dd_timer], a
-
-  ; set position
-  ld a, b
-  ld [dd_y], a
-  ld a, c
-  ld [dd_x], a
-
-  ld b, DD_D0_TILE
-  ld a, [d16]
-  add a, b ; d0 + roll value of d16
-  ld [dd_d16], a ; tile to display 
-
-  ret
   
   ; updates dice display if the timer is not 0
 dice_display_update:
index bea03966c9faa3271726554d8d2d5e5c7725d4b0..8033a52accf08dc0570b3333dd494ff626492473 100644 (file)
@@ -93,6 +93,16 @@ unit_demo_1_update:
   ; inputs
   ;   de: actor
 unit_draw:
+  ; first check if dd_timer is set
+  push de
+  ld hl, act_rt_dd_timer
+  add hl, de
+  ld a, [hl]
+  cp a, 0
+  pop de
+  jp nz, @unit_draw_dd
+
+
   push de
   ld hl, act_oam_tile
   add hl, de ; hl = tile 
@@ -106,6 +116,36 @@ unit_draw:
   ldnull bc
   ret
 
+@unit_draw_dd:
+  push de
+  
+  ld hl, act_rt_dd_d16
+  add hl, de
+  ; hl = d16
+  ld a, [hl+] ; a = tile
+  ; TODO: handle flags if ever needed 
+  
+  
+  pop de
+  push de
+  
+  ld b, a ; tile
+  ld c, 0 ; tile flags
+  call unit_generic_draw
+  
+  ; timer--
+  pop de 
+  push de
+  ld hl, act_rt_dd_timer
+  add hl, de ; de = timer
+  ld a, [hl]
+  dec a
+  ld [hl], a
+
+  pop de
+  ldnull bc
+  ret
+
   ; draws any unit
   ; inputs:
   ;  de: actor
@@ -552,7 +592,7 @@ unit_next_no_current:
         ld d, a ; d = roll value 
         pop af ; a = init value
         cp a, d
-        call nc, unit_dice_display_set
+        call nc, unit_dice_display_set_hl
         jr nc, @skip REL ; d < a
 
         ld [unit_next_best_init], a
@@ -682,17 +722,36 @@ unit_get_pos:
   ; inputs:
   ;   hl: unit
   ; preserves all registers
+unit_dice_display_set_hl:
+  push de 
+  push hl
+  pop de ; de = unit now
+  call unit_dice_display_set 
+  pop de ; de is restored
+  ret
+
+  ; same as unit_dice_display_set_hl 
+  ; but follows the regular calling conventions
+  ; inputs:
+  ;   de: unit
+  ; preserves all registers
 unit_dice_display_set:
   push_all
+
+  ld hl, act_rt_dd_d16
+  add hl, de ; hl = actor's dd runtime values 
+
+  ld b, DD_D0_TILE
+  ld a, [d16]
+  add a, b ; d0 + roll value of d16
+  ld [hl+], a ; store tile to draw 
   
-  ld de, act_pos_y
-  add hl, de
-  ld a, [hl+]
-  ld b, a
-  ld a, [hl]
-  ld c, a ; b/c = y/x
-  ld a, 0 ; no flags
-  call dice_display_set
+  ld a, DD_TIME
+  ld [hl+], a ; set timer
+
+  xor a, a
+  ; no flags
+  ld [hl+], a
 
   pop_all
   ret
index 7a1f3e91ad67275e2ed0f4c3654d29b81f28f950..c3f4253101e9ec4b7929fa5037373a5b620f048b 100644 (file)
@@ -16,9 +16,6 @@ update_game:
   call shadow_oam_clear
   call ui_display_current_unit
 
-
-  call dice_display_update
-
   ld hl, p0_units
   call units_update
   ld hl, p1_units