200 lines
7.7 KiB
Lua
200 lines
7.7 KiB
Lua
-- Control guide animation, in arcade frames: frames 0..419 are the both-sticks loop (left hand,
|
|
-- then right hand), frames 420..649 the 決定 loop. Each layer's pose(f) returns
|
|
-- x, y, scale, rotation (degrees, about the top-left corner) and alpha.
|
|
|
|
local M = {}
|
|
|
|
local function lerp(f, f0, f1, v0, v1)
|
|
if f <= f0 then return v0 end
|
|
if f >= f1 then return v1 end
|
|
return v0 + (v1 - v0) * (f - f0) / (f1 - f0)
|
|
end
|
|
|
|
-- the drum glow breathes with a 20 frame period: down to 0.5 at phase 9, back to 1 at phase 20
|
|
local function pulse(f)
|
|
local p = f % 20
|
|
if p < 9 then return 1 - 0.5 * p / 9 end
|
|
return 0.5 + 0.5 * (p - 9) / 11
|
|
end
|
|
|
|
-- 1 on the frame of a hit, easing back to 0 over the next five
|
|
local function press(f, hits)
|
|
for i = 1, #hits do
|
|
local t = f - hits[i]
|
|
if t >= 0 and t < 5 then return 1 - t / 5 end
|
|
end
|
|
return 0
|
|
end
|
|
|
|
local LEFT_HITS, RIGHT_HITS = { 60, 145 }, { 270, 355 }
|
|
local DECIDE_HIT = 520
|
|
|
|
-- the drum, always shown; it dips and shrinks on every hit
|
|
local function drum(f)
|
|
local ul, ur, ud = press(f, LEFT_HITS), press(f, RIGHT_HITS), press(f, { DECIDE_HIT })
|
|
return 47 + 3.33 * ul + 1.48 * ur + 5 * ud, 31 + 3.83 * ul + 3.82 * ur + 8.5 * ud,
|
|
1 - 0.02 * (ul + ur) - 0.0417 * ud, 0, 1
|
|
end
|
|
|
|
-- the cyan flash on each hit: grows around a fixed centre while it fades
|
|
local FLASH = { { 60, 115.5 }, { 145, 115.5 }, { 270, 218.5 }, { 355, 218.5 } }
|
|
local function flash(f)
|
|
for i = 1, #FLASH do
|
|
local t = f - FLASH[i][1]
|
|
if t >= -1 and t < 10 then
|
|
local sc = (t < 5) and lerp(t, 0, 5, 0.8333, 1.25) or lerp(t, 5, 10, 1.25, 1.5)
|
|
local a = ((t < 0) and lerp(t, -1, 0, 0, 1) or 1) * (1 - lerp(t, 5, 10, 0, 1))
|
|
return FLASH[i][2] - 48 * sc, 66.5 - 48 * sc, sc, 0, a
|
|
end
|
|
end
|
|
return 0, 0, 1, 0, 0
|
|
end
|
|
|
|
-- cyan rims beside the drum, one per hand, pulsing while that hand is shown
|
|
local function rim_left(f)
|
|
local u = press(f, LEFT_HITS)
|
|
return 55 + 3.17 * u, 27 + 3.91 * u, 1 - 0.02 * u, 0,
|
|
pulse(f) * lerp(f, 0, 9, 0, 1) * (1 - lerp(f, 200, 209, 0, 1))
|
|
end
|
|
|
|
local function rim_right(f)
|
|
local u = press(f, RIGHT_HITS)
|
|
return 167 - 0.9 * u, 27 + 3.9 * u, 1 - 0.02 * u, 0,
|
|
pulse(f) * lerp(f, 210, 219, 0, 1) * (1 - lerp(f, 410, 420, 0, 1))
|
|
end
|
|
|
|
-- the arrow floats in at the start of each swing, glides toward the drum and fades
|
|
local ARROWS = {
|
|
{ 35, 40, 40, 55, 95, 100, 213, 61, 196, 1, 0 },
|
|
{ 125, 130, 130, 145, 180, 190, 213, 61, 196, 1, 0 },
|
|
{ 244, 250, 250, 265, 310, 315, 341, 221, 358, 281, -180 },
|
|
{ 335, 340, 340, 354, 390, 400, 341, 221, 358, 281, -180 },
|
|
}
|
|
local function arrow(f)
|
|
for i = 1, #ARROWS do
|
|
local A = ARROWS[i]
|
|
if f >= A[1] and f < A[6] then
|
|
local a = lerp(f, A[1], A[2], 0, 1) * (1 - lerp(f, A[5], A[6], 0, 1))
|
|
return lerp(f, A[3], A[4], A[7], A[9]), lerp(f, A[3], A[4], A[8], A[10]), 1, A[11], a
|
|
end
|
|
end
|
|
return 0, 0, 1, 0, 0
|
|
end
|
|
|
|
-- the orange glow behind the drum in the 決定 loop, and its ripple on the hit
|
|
local function glow(f)
|
|
if f < 420 then return 0, 0, 1, 0, 0 end
|
|
if f < 520 then
|
|
local a = (f < 440) and lerp(f, 420, 440, 0, 1) or 0.5 + 0.5 * math.abs((f - 440) % 20 - 10) / 10
|
|
return 87, 51, 1, 0, a
|
|
end
|
|
local t = f - 520
|
|
local sc = (t < 5) and lerp(t, 0, 5, 1, 1.625) or lerp(t, 5, 20, 1.625, 1.75)
|
|
local a = (t < 5) and lerp(t, 0, 5, 1, 0.75) or lerp(t, 5, 20, 0.75, 0)
|
|
local x = (t < 5) and lerp(t, 0, 5, 87, 37) or lerp(t, 5, 20, 37, 27)
|
|
local y = (t < 5) and lerp(t, 0, 5, 51, 5.376) or lerp(t, 5, 20, 5.376, -3.749)
|
|
return x, y, sc, 0, a
|
|
end
|
|
|
|
-- a hand's raised stick: fades in, leans toward the drum, vanishes for the ten frames around each hit
|
|
-- (the swing poses take over), returns raised, then fades out
|
|
local HANDS = {
|
|
{ shift = 0, hits = { 60, 145 }, p0 = { 108, 83 }, p1 = { 100.2, 55 }, p2 = { 100, 53 } },
|
|
{ shift = 210, hits = { 270, 354 }, p0 = { 178, 83 }, p1 = { 185.5, 54.95 }, p2 = { 186, 53 } },
|
|
}
|
|
|
|
local function raised(h)
|
|
return function(f)
|
|
local g = f - h.shift
|
|
local a = lerp(g, 0, 20, 0, 1) * (1 - lerp(g, 180, 190, 0, 1))
|
|
for i = 1, #h.hits do
|
|
if f >= h.hits[i] - 5 and f < h.hits[i] + 5 then a = 0 end
|
|
end
|
|
local x, y
|
|
if g < 40 then x, y = h.p0[1], h.p0[2]
|
|
elseif g < 54 then x, y = lerp(g, 40, 54, h.p0[1], h.p1[1]), lerp(g, 40, 54, h.p0[2], h.p1[2])
|
|
else x, y = lerp(g, 54, 64, h.p1[1], h.p2[1]), lerp(g, 54, 64, h.p1[2], h.p2[2]) end
|
|
return x, y, 1, 0, a
|
|
end
|
|
end
|
|
|
|
-- the stick mid-swing before a hit (-5..0 frames) and after it (0..5)
|
|
local function swing(h, after)
|
|
return function(f)
|
|
for i = 1, #h.hits do
|
|
local t = f - h.hits[i]
|
|
if (after and t >= 0 and t < 5) or (not after and t >= -5 and t < 0) then
|
|
return h.p2[1], h.p2[2], 1, 0, 1
|
|
end
|
|
end
|
|
return 0, 0, 1, 0, 0
|
|
end
|
|
end
|
|
|
|
-- the 決定 sticks: raised, tilting down on the hit, then three held poses
|
|
local TAP_LEFT = { x = 47, y = 119, tx = 59.85, ty = 96.65, rot = 5.526, hold_x = 54 }
|
|
local TAP_RIGHT = { x = 191, y = 119, tx = 178.6, ty = 106, rot = -5.527, hold_x = 184 }
|
|
|
|
local function tap_raised(s)
|
|
return function(f)
|
|
if f >= 505 then return 0, 0, 1, 0, 0 end
|
|
return lerp(f, 490, 504, s.x, s.tx), lerp(f, 490, 504, s.y, s.ty), 1, lerp(f, 490, 504, 0, s.rot),
|
|
lerp(f, 420, 440, 0, 1)
|
|
end
|
|
end
|
|
|
|
local function tap_hold(s, from, to)
|
|
return function(f)
|
|
local a = (f >= from and f < to) and 1 or 0
|
|
if to == 619 and f >= from then a = 1 - lerp(f, 619, 630, 0, 1) end
|
|
return s.hold_x, 99.5, 1, 0, a
|
|
end
|
|
end
|
|
|
|
-- the 決定 pill and its blink press with the drum
|
|
local function pill(f)
|
|
local sc = (f < 520) and 1 or lerp(f, 520, 525, 0.9498, 1)
|
|
return 167 - 108 * sc, 237 - 36 * sc, sc, 0, lerp(f, 470, 490, 0, 1) * (1 - lerp(f, 619, 630, 0, 1))
|
|
end
|
|
|
|
local function blink(f)
|
|
local sc = (f < 520) and 1 or lerp(f, 520, 525, 0.9499, 1)
|
|
local a
|
|
if f < 525 then a = lerp(f, 520, 525, 0, 0.5)
|
|
elseif f < 530 then a = lerp(f, 525, 530, 0.5, 1)
|
|
elseif f < 540 then a = lerp(f, 530, 540, 1, 0.5)
|
|
elseif f < 550 then a = lerp(f, 540, 550, 0.5, 1)
|
|
else a = lerp(f, 550, 570, 1, 0) end
|
|
return 167 - 108 * sc, 237 - 36 * sc, sc, 0, a
|
|
end
|
|
|
|
-- draw order, bottom to top
|
|
M.layers = {
|
|
{ tex = "guide_84", pose = flash },
|
|
{ tex = "guide_68", mirror = true, pose = rim_right },
|
|
{ tex = "guide_68", pose = rim_left },
|
|
{ tex = "guide_74", mirror = true, pose = rim_right },
|
|
{ tex = "guide_74", pose = rim_left },
|
|
{ tex = "guide_49", pose = drum },
|
|
{ tex = "guide_80", pose = arrow },
|
|
{ tex = "guide_51", pose = glow },
|
|
{ tex = "guide_78", pose = raised(HANDS[1]) },
|
|
{ tex = "guide_82", pose = swing(HANDS[1], false) },
|
|
{ tex = "guide_86", pose = swing(HANDS[1], true) },
|
|
{ tex = "guide_78", mirror = true, pose = raised(HANDS[2]) },
|
|
{ tex = "guide_82", mirror = true, pose = swing(HANDS[2], false) },
|
|
{ tex = "guide_86", mirror = true, pose = swing(HANDS[2], true) },
|
|
{ tex = "guide_53", mirror = true, pose = tap_raised(TAP_RIGHT) },
|
|
{ tex = "guide_59", mirror = true, pose = tap_hold(TAP_RIGHT, 505, 515) },
|
|
{ tex = "guide_61", mirror = true, pose = tap_hold(TAP_RIGHT, 515, 520) },
|
|
{ tex = "guide_63", mirror = true, pose = tap_hold(TAP_RIGHT, 520, 619) },
|
|
{ tex = "guide_53", pose = tap_raised(TAP_LEFT) },
|
|
{ tex = "guide_59", pose = tap_hold(TAP_LEFT, 505, 515) },
|
|
{ tex = "guide_61", pose = tap_hold(TAP_LEFT, 515, 520) },
|
|
{ tex = "guide_63", pose = tap_hold(TAP_LEFT, 520, 619) },
|
|
{ tex = "guide_65", pose = blink },
|
|
{ tex = "guide_57", pose = pill, pill = true },
|
|
}
|
|
|
|
return M
|