actor: Added semi-smooth sub tile animation
authorLukas Krickl <lukas@krickl.dev>
Fri, 27 Jun 2025 15:57:51 +0000 (17:57 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 27 Jun 2025 15:57:51 +0000 (17:57 +0200)
src/defs.s
src/unit.s

index 7544a69b16b57b002cc85418eebd90054e7f5640..7edd11af8862a995d6fbcfc619143d52588887f5 100644 (file)
 
   ; sub-tile drawing vars
   ; during this animation the actor is already technically in its new 
-  ; location.
-  ; ab000000: direction bits (a == 0/1 -> up/down; b == 0/1 -> left/right)
-  ; 00nnn000: current tile offset y position
-  ; 00000nnn: currnet tile offset x position
+  ; location. the real location offset can be calculated with 
+  ; the st_time in the actor if sub tile enable is set
+  ; ab0de000: direction bits (a == 1 -> up; b == 1 -> down; d == 1 -> left; e == 1 -> right)
+  ; 00c00000: c: sub tile enabled
 .de act_rt_sub_tile, 1
 
   ; stats1
index 3a9149595dd08879fce71e73ab66046445420b69..7768801dbb26da76c2f215974eaa876dd2d49874 100644 (file)
@@ -80,6 +80,68 @@ unit_draw:
   ldnull bc
   ret
 
+  ; adjust an object's position 
+  ; based on sub-tile state
+  ; inputs:
+  ;   de: actor
+  ;   hl: object in shadow oam
+unit_generic_draw_adjust_subtile:
+  ; check if actor is in sub-tile mode
+  push hl
+  push de
+  
+  ld hl, act_rt_sub_tile
+  add hl, de
+  ld a, [hl] ; a = rt_sub_tile value
+  pop de ; de = actor st_time
+  pop hl ; hl = obj
+  ld b, a ; b = rt_sub_tile value
+  cp a, 0
+  ; if this value is 0 we are not movin
+  jp z, @done 
+
+  ld a, [de] ; load timer
+  div16 a ; a = timer/16 giving us a pixel offset
+  ld c, a ; c = timer/16
+
+  ; test bit 7 for up
+  bit 7, b
+  jr z, @not_up REL
+    ld a, [hl] ; a = obj y
+    add a, c ; a += offset
+    ld [hl], a
+@not_up:
+  
+  ; test bit 6 for down
+  bit 6, b
+  jr z, @not_down REL
+    ld a, [hl]
+    sub a, c ; a -= offset
+    ld [hl], a
+@not_down:
+  
+  inc hl ; hl = x position
+
+  ; test bit 4 for left
+  bit 4, b
+  jr z, @not_left REL
+    ld a, [hl]
+    add a, c ; a += offset
+    ld [hl], a
+@not_left:
+
+  ; test bit 3 for right
+  bit 3, b
+  jr z, @not_right REL
+    ld a, [hl]
+    sub a, c ; a += offset
+    ld [hl], a
+@not_right:
+
+@done:
+
+  ret
+
   ; draws any unit
   ; inputs:
   ;  de: actor
@@ -87,6 +149,8 @@ unit_draw:
   ;   c: flags
 unit_generic_draw:
 #define TMP_OAMFLAG_PRIO scratch
+  push de ; save actor
+
   xor a, a
   ld [TMP_OAMFLAG_PRIO], a
 
@@ -133,7 +197,13 @@ unit_generic_draw:
   ; set flags
   ld a, [TMP_OAMFLAG_PRIO]
   or a, c
-  ld [hl+], a
+  ld [hl], a
+  
+  dec hl
+  dec hl
+  dec hl ; object - 3 go back to start
+  pop de
+  call unit_generic_draw_adjust_subtile
 
   ldnull bc
   ret
@@ -363,8 +433,8 @@ unit_try_move_up:
   dec a 
   ld [hl], a
   
-  ; not bits set
-  ld a, 0b00000000
+  ; enable subtile up
+  ld a, 0b10100000
   call unit_set_delay_to_active_speed
 
   ret
@@ -383,8 +453,8 @@ unit_try_move_down:
   inc a
   ld [hl], a
 
-  ; set down bit
-  ld a, 0b10000000
+  ; enable subtile down
+  ld a, 0b01100000
   call unit_set_delay_to_active_speed
   
   ret
@@ -402,9 +472,9 @@ unit_try_move_left:
   
   dec a
   ld [hl], a
-  
-  ; no bits set
-  ld a, 0b00000000
+  ; enable subtile left
+  ld a, 0b00110000
   call unit_set_delay_to_active_speed
   
   ret
@@ -424,8 +494,8 @@ unit_try_move_right:
   inc a
   ld [hl], a
 
-  ; set right bit
-  ld a, 0b01000000
+  ; enable subtile right
+  ld a, 0b00101000
   call unit_set_delay_to_active_speed
 
   ret 
@@ -486,6 +556,13 @@ unit_scroll_center:
   ; inputs:
   ;   de: unit
 unit_switch_to_active:
+  push de
+  ld hl, act_rt_sub_tile
+  add hl, de
+  xor a, a
+  ld [hl], a ; clear sub_tile values
+  pop de
+
   ld hl, act_st_active
   add hl, de ; hl = st_active ptr
   ld a, [hl+]