From: Lukas Krickl Date: Fri, 27 Jun 2025 15:57:51 +0000 (+0200) Subject: actor: Added semi-smooth sub tile animation X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=13d64c6d7b7b33c946fce244e6b6199b4e216e75;p=gbrg%2F.git actor: Added semi-smooth sub tile animation --- diff --git a/src/defs.s b/src/defs.s index 7544a69..7edd11a 100644 --- a/src/defs.s +++ b/src/defs.s @@ -145,10 +145,10 @@ ; 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 diff --git a/src/unit.s b/src/unit.s index 3a91495..7768801 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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+]