; 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
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
; c: flags
unit_generic_draw:
#define TMP_OAMFLAG_PRIO scratch
+ push de ; save actor
+
xor a, a
ld [TMP_OAMFLAG_PRIO], a
; 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
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
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
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
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
; 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+]