Files
YataiDON14/Scripts/retry_game/retry_game.lua
T
2026-11-22 19:25:31 -05:00

706 lines
25 KiB
Lua

RetryGame = {}
RetryGame.__index = RetryGame
-- Taiko 14 revival.swg: Don eats the room's dishes while you drum, then the big meat. Positions are the swg's
-- 640x480 px (K scales them to the screen), times are 60 fps frames from the scene start.
local PATH = "retry_game/"
local FRAME_MS = 1000 / 60
local ROLL_AT, ROLL_LEN = 29, 40
local DISHES_AT = 99
local SURPRISE_AT = DISHES_AT + 56
local RULE_OUT_AT = 250
local READY_AT = 285
local GO_AT = READY_AT + 25
local COUNT_LEN = 300
local END_AT = GO_AT + COUNT_LEN
local HURRY_AT = GO_AT + 150
local EAT_HOLD = 20
local CHEW_LEN = 40
local FAIL_HOLD, SUCCESS_HOLD = 240, 210
local DON_X, DON_Y = 225.6, 71.6
local MEAT_X, MEAT_Y = 313, 265
local DISH_FALL = 520
local CX = 320
-- where each dish sits in front of Don (top-left)
local FRONT = {
cake = { 265.0, 231.2 }, wagashi = { 200.1, 208.2 }, pan = { 260.4, 247.2 }, omusubi = { 205.2, 212.3 },
takoyaki = { 223.1, 214.3 }, karaage = { 163.9, 214.2 }, mabo = { 198.5, 179.9 }, nabe = { 189.4, 206.2 },
kanitama = { 201.2, 179.9 }, una = { 212.3, 182.9 }, shumai = { 186.0, 189.9 }, kaisen = { 215.5, 171.9 },
ten = { 194.4, 189.9 }, chuka = { 214.4, 217.9 }, nishin = { 188.4, 198.3 }, tsukimi = { 215.4, 178.8 },
negitoro = { 213.4, 169.0 }, oyako = { 213.4, 170.9 },
}
local DISHES = { "cake", "wagashi", "pan", "omusubi", "takoyaki", "karaage", "mabo", "nabe", "kanitama", "una",
"shumai", "kaisen", "ten", "chuka", "nishin", "tsukimi", "negitoro", "oyako" }
-- the tossed meat (centre x, y, turn): sparse points of the arc, the rest is interpolated
local TOSS = { { 0, 313, 267, 0 }, { 8, 258, 244, 19 }, { 14, 190, 165, 53 }, { 20, 168, 76, 83 },
{ 28, 178, -21, 114 }, { 36, 212, -82, 137 } }
local MISS_FALL = { { 52, 286, -89, -30 }, { 60, 295, -7, -17 }, { 64, 306, 97, 0 }, { 68, 301, 107, -5 },
{ 76, 263, 94, -28 }, { 84, 244, 111, -27 }, { 92, 219, 198, -25 }, { 98, 211, 307, -23 },
{ 102, 214, 348, 0 }, { 106, 214, 338, 0 }, { 110, 214, 344, 0 } }
local BONE_FALL = { { 86, 271, 103, 28 }, { 94, 292, 240, 15 }, { 102, 314, 372, 2 }, { 104, 316, 380, 0 },
{ 106, 316, 370, 0 }, { 110, 316, 389, 0 } }
-- crumbs per chomp: start and end centre
local CRUMBS = { { 299, 221, 194, 124, 0 }, { 304, 203, 212, 49, 1 }, { 322, 210, 390, 92, 0 },
{ 347, 206, 437, 134, 1 } }
local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end
local function lerp(a, b, p) return a + (b - a) * p end
local function ease_in(p) return p * p end
local function ease_out(p) return 1 - (1 - p) * (1 - p) end
local function seg(t, from, len) return clamp((t - from) / len, 0, 1) end
local function path(keys, f)
if f <= keys[1][1] then return keys[1][2], keys[1][3], keys[1][4] end
for i = 2, #keys do
local a, b = keys[i - 1], keys[i]
if f <= b[1] then
local p = (f - a[1]) / (b[1] - a[1])
return lerp(a[2], b[2], p), lerp(a[3], b[3], p), lerp(a[4], b[4], p)
end
end
local k = keys[#keys]
return k[2], k[3], k[4]
end
-- text pop: 0.1 -> 1.5 -> 1 (-> 1.2 -> 1 with a second bump)
local function pop_scale(e, bump)
if e < 14 then return lerp(0.1, 1.5, ease_out(e / 14)), e / 14 end
if e < 21 then return lerp(1.5, 1, ease_in((e - 14) / 7)), 1 end
if not bump then return 1, 1 end
if e < 27 then return lerp(1, 1.2, ease_out((e - 21) / 6)), 1 end
if e < 32 then return lerp(1.2, 1, ease_in((e - 27) / 5)), 1 end
return 1, 1
end
-- digit pop, bottom-anchored: up in 3 frames, down in 6
local function digit_pop(e, sx, sy)
if e < 0 or e >= 9 then return 1, 1 end
local p = e < 3 and ease_out(e / 3) or 1 - ease_in((e - 3) / 6)
return lerp(1, sx, p), lerp(1, sy, p)
end
local function snd(name, kind)
if audio.has_sound(name) then audio.play_sound(name, kind or "sound") end
end
function RetryGame.new(player_num, norma)
local self = setmetatable({}, RetryGame)
self.norma = math.max(1, norma or 30)
self.thrill = math.floor(self.norma * 0.75)
self.K = tex.get_screen_width() / 640
self.tex, self.info = {}, {}
for _, key in ipairs({ "background/sea", "background/room", "background/tint", "don/lie", "don/shock",
"don/front", "don/collapse", "don/catch", "don/drop", "don/crumb", "don/puff", "don/meat",
"callout/rule", "callout/ready", "callout/go", "callout/mash", "callout/failure", "callout/success",
"timer/digits", "timer/time_up" }) do
self:load(key)
end
self.dishes = {}
for _, name in ipairs(DISHES) do
self:load("food/" .. name)
self:load("food/" .. name .. "_plate")
self.dishes[#self.dishes + 1] = { name = name }
end
self.order = {}
for i = 1, #self.dishes do self.order[i] = i end
for i = #self.order, 2, -1 do
local j = math.random(i)
self.order[i], self.order[j] = self.order[j], self.order[i]
end
self.t0 = nil
self.f = 0
self.hits = 0
self.course = 0
self.last_hit = -1e9
self.chomp_at = nil
self.crumbs = {}
self.meat_at = nil
self.hold_at = nil
self.result = nil
self.result_at = nil
self.toss_at = nil
self.text_at = nil
self.finished = false
self.fired = {}
return self
end
function RetryGame:load(key)
local folder, name = key:match("([^/]+)/(.+)")
self.tex[key] = tex.get_texture(PATH .. key)
local info = tex.get_texture_info(folder, name)
self.info[key] = info and { info.x[1] or 0, info.y[1] or 0, info.x2[1] or 0, info.y2[1] or 0 } or { 0, 0, 0, 0 }
end
-- top-left (x, y) in swg px, stretched by (sx, sy) from there
function RetryGame:tl(key, x, y, o)
o = o or {}
local t = self.tex[key]
if not t then return end
local i = self.info[key]
local sx, sy = o.sx or 1, o.sy or 1
tex.draw_texture(t, { frame = o.frame or 0, x = x * self.K - i[1], y = y * self.K - i[2], x2 = i[3] * (sx - 1),
y2 = i[4] * (sy - 1), fade = o.fade, mirror = o.mirror })
end
-- centred on (cx, cy) swg px
function RetryGame:ctr(key, cx, cy, o)
o = o or {}
local t = self.tex[key]
if not t then return end
local i = self.info[key]
local sx, sy = o.sx or o.s or 1, o.sy or o.s or 1
tex.draw_texture(t, { frame = o.frame or 0, x = cx * self.K - i[1], y = cy * self.K - i[2],
x2 = i[3] * (sx - 1), y2 = i[4] * (sy - 1), origin = { i[3] * sx / 2, i[4] * sy / 2 },
rotation = o.rot or 0, fade = o.fade, mirror = o.mirror })
end
-- swg size of a texture
function RetryGame:size(key)
local i = self.info[key]
return i[3] / self.K, i[4] / self.K
end
function RetryGame:once(key, cond, fn)
if cond and not self.fired[key] then
self.fired[key] = true
fn()
end
end
function RetryGame:counting()
return self.f >= GO_AT and self.f < END_AT and not self.result
end
function RetryGame:hit()
if not self:counting() then return end
self.hits = self.hits + 1
if self.f - self.last_hit >= EAT_HOLD and not self.meat_at then snd("eat") end
self.last_hit = self.f
local dish = self.dishes[self.order[self.course]]
if dish and dish.front_at and not dish.eaten_at then dish.shake_at = self.f end
self:advance_course()
end
-- dish k goes to the front at hits = (k - 1) * thrill / #dishes; at thrill the meat comes
function RetryGame:advance_course()
local n = #self.dishes
local want = math.min(n + 1, math.floor(n * self.hits / self.thrill) + 1)
while self.course < want do
local prev = self.dishes[self.order[self.course]]
if prev then prev.eaten_at = self.f end
self.course = self.course + 1
local nxt = self.dishes[self.order[self.course]]
if nxt then
nxt.front_at = self.f
else
self.meat_at = self.f
end
end
end
function RetryGame:update(current_ms)
if not self.t0 then self.t0 = current_ms end
self.f = (current_ms - self.t0) / FRAME_MS
local f = self.f
if f >= GO_AT and self.course == 0 then self:advance_course() end
if self.meat_at and not self.hold_at and f >= self.meat_at + 93 then self.hold_at = f end
if not self.result then
if self.hold_at and self.hits >= self.norma * 2 and f < END_AT then
self:decide("success", f)
elseif f >= END_AT then
if not self.meat_at then
self:decide("failure", END_AT)
elseif self.hold_at then
self:decide(self.hits >= self.norma and "success" or "failure", math.max(END_AT, self.hold_at),
true)
end
end
end
if self.result and not self.text_at then
if not self.toss_at then
self.text_at = self.result_at + 10
elseif self.result == "success" then
if f >= self.toss_at + 110 then self.text_at = self.toss_at + 110 end
elseif f >= self.toss_at + 82 then
self.text_at = self.toss_at + 82
end
end
if self.text_at then
local hold = self.result == "success" and SUCCESS_HOLD or FAIL_HOLD
if f >= self.text_at + hold then self.finished = true end
end
self:sounds()
end
function RetryGame:decide(result, at, chew)
self.result = result
self.result_at = at
if self.meat_at then self.toss_at = at + (chew and CHEW_LEN or 0) end
end
function RetryGame:sounds()
local f = self.f
self:once("huh", f >= ROLL_AT, function() snd("voice_huh", "voice") end)
self:once("set", f >= DISHES_AT + 5, function() snd("dishes_set") end)
self:once("title", f >= DISHES_AT + 3, function()
snd("fanfare")
snd("voice_title", "voice")
end)
self:once("ready", f >= READY_AT, function() snd("voice_ready", "voice") end)
self:once("go", f >= GO_AT, function()
snd("voice_go", "voice")
snd("bgm", "music")
end)
self:once("hurry", f >= HURRY_AT and not self.meat_at and not self.result, function()
snd("voice_hurry", "voice")
end)
for k = 3, 1, -1 do
self:once("count" .. k, f >= END_AT - k * 60 and not self.result, function() snd("countdown") end)
end
self:once("stop", self.result or f >= END_AT, function()
if audio.is_sound_playing("bgm") then audio.stop_sound("bgm") end
end)
self:once("time_up", f >= END_AT and (not self.result or self.result_at >= END_AT), function()
snd("time_up")
end)
if self.meat_at then
for _, d in ipairs({ 64, 82 }) do
self:once("meat_eat" .. d, f >= self.meat_at + d, function() snd("eat") end)
end
end
if self.toss_at then
if self.toss_at > self.result_at then
for _, d in ipairs({ 0, 17, 28 }) do
self:once("chew" .. d, f >= self.result_at + d, function() snd("eat") end)
end
end
self:once("toss", f >= self.toss_at, function() snd("toss") end)
if self.result == "success" then
self:once("munch", f >= self.toss_at + 47, function() snd("voice_munch", "voice") end)
else
self:once("bonk", f >= self.toss_at + 64, function() snd("bonk") end)
end
end
self:once("result", self.text_at and f >= self.text_at + 2, function()
if self.result == "success" then
snd("success")
snd("voice_clear", "voice")
else
snd("failure")
snd("voice_fail", "voice")
end
end)
end
function RetryGame:is_finished() return self.finished end
function RetryGame:is_success() return self.result == "success" end
function RetryGame:chara_pos() return nil end
function RetryGame:phase()
if self.result then return self.result end
return self:counting() and "count" or "wait"
end
function RetryGame:draw_background()
local f = self.f
self:tl("background/room", 0, 0, { fade = f >= DISHES_AT and 1 or 0 })
local sea = seg(f, 0, 11) * (1 - seg(f, DISHES_AT + 3, 10))
if sea > 0 then self:tl("background/sea", 0, 0, { fade = sea }) end
if self.result == "success" and self.text_at then
local p = seg(f, self.text_at + 3, 18)
if p > 0 then
tex.draw_texture(self.tex["background/tint"], { color = { 60, 30, 10, 255 }, fade = p,
blend = "additive" })
end
end
end
-- the eating loop: cheeks full for 3 frames, chewing for 7, squashed then stretched about the feet
function RetryGame:draw_chomp(frame_base)
local p = (self.f - self.chomp_at) % 10
local sy = p < 5 and 1 - 0.05 * math.sin(math.pi * p / 5) or 1 + 0.05 * math.sin(math.pi * (p - 5) / 5)
local _, h = self:size("don/front")
self:tl("don/front", DON_X, DON_Y + h * (1 - sy), { frame = p < 3 and frame_base or 2, sy = sy })
end
function RetryGame:spawn_crumbs()
local loop = math.floor((self.f - self.chomp_at) / 10)
if loop ~= self.crumb_loop then
self.crumb_loop = loop
self.crumbs[#self.crumbs + 1] = self.chomp_at + loop * 10 + 2
if #self.crumbs > 3 then table.remove(self.crumbs, 1) end
end
end
function RetryGame:draw_crumbs()
for _, at in ipairs(self.crumbs) do
local e = self.f - at
if e >= 0 and e < 13 then
local p = ease_out(e / 13)
for _, c in ipairs(CRUMBS) do
self:ctr("don/crumb", lerp(c[1], c[3], p), lerp(c[2], c[4], p),
{ frame = c[5], s = lerp(1, 0.8, p), rot = lerp(180, 0, p), fade = 1 - p })
end
end
end
end
function RetryGame:draw_intro_don()
local f = self.f
if f < ROLL_AT then return end
local e = f - ROLL_AT
if e < ROLL_LEN then
local x = e < 35 and lerp(-6, 244, ease_out(e / 35)) or lerp(244, 224, ease_in((e - 35) / 5))
local y = lerp(58, 118, ease_out(math.min(e, 35) / 35))
self:tl("don/lie", x, y)
return
end
local s = f - SURPRISE_AT
if s < 0 then
self:tl("don/lie", 224, 118)
elseif s < 40 then
local frame = s < 9 and 0 or s < 14 and 1 or s < 19 and 2 or 3
self:tl("don/lie", 224, 118, { frame = frame })
if s >= 14 and s < 38 then
local w = self:size("don/shock")
self:tl("don/shock", 484.6 - w, 34.7, { mirror = "horizontal", fade = lerp(1, 0.3, (s - 14) / 24) })
end
else
self:tl("don/front", DON_X, DON_Y)
end
end
function RetryGame:meat_stage()
if not self.meat_at then return 0 end
return clamp(math.floor((self.f - self.meat_at - 64) / 10) + 1, 0, 3)
end
function RetryGame:draw_counting_don()
local f = self.f
local eating = f - self.last_hit < EAT_HOLD
if self.meat_at then
local e = f - self.meat_at
if e < 64 then
self:tl("don/front", DON_X, DON_Y, { frame = 1 })
self:draw_meat_drop(e)
return
end
if e < 93 or eating or (self.result and self.toss_at and f < self.toss_at) then
self.chomp_at = self.chomp_at or f
self:draw_chomp(1)
else
self.chomp_at = nil
self:tl("don/front", DON_X, DON_Y, { frame = 2 })
end
local bob = e < 93 and math.sin(math.pi * ((e - 64) % 10) / 10) * -4 or 0
self:ctr("don/meat", MEAT_X, MEAT_Y + bob, { frame = self:meat_stage() })
return
end
if eating then
self.chomp_at = self.chomp_at or f
self:spawn_crumbs()
self:draw_chomp(1)
else
self.chomp_at = nil
self.crumb_loop = nil
self:tl("don/front", DON_X, DON_Y)
end
end
-- the meat drops in front of Don 22 frames in, lands at 30, squashes and bounces till 50
function RetryGame:draw_meat_drop(e)
if e < 22 then return end
local d = e - 22
if d < 8 then
self:ctr("don/meat", MEAT_X, lerp(38, MEAT_Y + 22, ease_in(d / 8)), { fade = lerp(0.11, 1, d / 8) })
return
end
local sy, y = 1, MEAT_Y
if d < 12 then
sy = lerp(1, 0.9, (d - 8) / 4)
elseif d < 22 then
sy = lerp(0.9, 1.083, ease_out((d - 12) / 10))
y = lerp(MEAT_Y + 22, MEAT_Y - 15, ease_out((d - 12) / 10))
elseif d < 30 then
sy = lerp(1.083, 1, (d - 22) / 8)
y = lerp(MEAT_Y - 15, MEAT_Y, ease_in((d - 22) / 8))
end
self:ctr("don/meat", MEAT_X, y, { sy = sy })
end
-- the last bite: toss the meat, leap after it off the top, land chewing, the bone drops, then hop for joy
function RetryGame:draw_catch(e)
local x, y, sy, frame = 185.9, 15.6, 1, 0
if e < 5 then frame = 0
elseif e < 9 then frame = 1
elseif e < 13 then frame = 2
elseif e < 19 then frame = 3
elseif e < 21 then frame = 4
elseif e < 27 then
frame = 1
local p = seg(e, 21, 6)
y, sy = lerp(15.6, 36.4, p), lerp(1, 0.92, p)
elseif e < 51 then
frame = 5
local p = ease_out(seg(e, 27, 18))
y, sy = lerp(-0.4, -254.4, p), lerp(0.9, 1, p)
elseif e < 73 then
frame = 6
y = lerp(-254.4, -14.4, ease_in(seg(e, 51, 21)))
elseif e < 120 then
frame = 7
local p = ease_out(seg(e, 73, 8))
y, sy = lerp(37, 15.6, p), lerp(0.921, 1, p)
else
local h = (e - 120) % 46
if h < 6 then
frame = 8
local p = h / 6
y, sy = lerp(15.6, 37.3, p), lerp(1, 0.917, p)
elseif h < 36 then
frame, x = 9, 170.9
y = -14.4 - 70 * math.sin(math.pi * (h - 6) / 30)
else
frame = 8
local p = ease_out((h - 36) / 10)
y, sy = lerp(41.6, 15.6, p), lerp(0.9, 1, p)
end
end
self:tl("don/catch", x, y, { frame = frame, sy = sy })
if e < 36 then
local mx, my, r = path(TOSS, e)
self:ctr("don/meat", mx, my, { frame = 3, rot = r })
elseif e >= 86 then
local mx, my, r = path(BONE_FALL, e)
self:ctr("don/meat", mx, my, { frame = 4, rot = r })
end
end
-- the missed last bite: toss, jump for it, it lands on Don's head and he topples
function RetryGame:draw_miss(e)
local x, y, sy, frame = 177.9, 16.6, 1, 0
if e < 6 then frame, x, y = 0, 163.9, 20.6
elseif e < 8 then frame = 1
elseif e < 12 then frame = 2
elseif e < 26 then
frame = 3
local p = seg(e, 18, 6)
y, sy = lerp(16.6, 35, p), lerp(1, 0.923, p)
elseif e < 46 then
frame = 4
local p = ease_out(seg(e, 26, 16))
y, sy = lerp(42.6, -73.4, p), lerp(0.9, 1, p)
elseif e < 62 then
frame = 5
y = lerp(-73.4, 46.6, ease_in(seg(e, 46, 14)))
elseif e < 68 then
frame = 6
local p = seg(e, 62, 4)
y, sy = lerp(40.3, 56.3, p), lerp(1, 0.931, p)
elseif e < 78 then
frame = 7
local p = seg(e, 68, 4)
y, sy = lerp(56.3, 39.6, p), lerp(0.931, 1, p)
elseif e < 82 then
frame, y = 8, 39.6
else
frame, x, y = 9, 157.9, 29.6
end
self:tl("don/drop", x, y, { frame = frame, sy = sy })
if e < 36 then
local mx, my, r = path(TOSS, e)
self:ctr("don/meat", mx, my, { frame = 3, rot = r })
elseif e >= 52 then
local mx, my, r = path(MISS_FALL, e)
self:ctr("don/meat", mx, my, { frame = 3, rot = r })
end
end
-- no last food: Don droops, collapses and lets out a sigh
function RetryGame:draw_collapse(e)
if e < 9 then
local sy = lerp(1, 0.912, e / 9)
self:tl("don/front", DON_X, lerp(74.1, 88.9, e / 9), { frame = 3, sy = sy })
return
end
local p = seg(e, 9, 4)
self:tl("don/collapse", 221.6, lerp(94.9, 73.7, p), { sy = lerp(0.9, 1, p) })
local s = e - 15
if s >= 0 and s < 28 then
local q = s / 28
local fade = s < 20 and lerp(0.3, 0.76, s / 20) or lerp(0.76, 0.1, (s - 20) / 8)
self:ctr("don/puff", lerp(310, 260, ease_out(q)), lerp(240, 185, ease_out(q)),
{ s = lerp(0.2, 1.46, ease_out(q)), fade = fade, mirror = "horizontal" })
end
end
function RetryGame:draw_don()
local f = self.f
if self.toss_at and f >= self.toss_at then
if self.result == "success" then self:draw_catch(f - self.toss_at) else self:draw_miss(f - self.toss_at) end
elseif self.result == "failure" and not self.meat_at then
self:draw_collapse(f - self.result_at)
elseif f >= GO_AT then
self:draw_counting_don()
else
self:draw_intro_don()
end
self:draw_crumbs()
end
function RetryGame:draw_dish(dish)
local f = self.f
if f < DISHES_AT then return end
local key = "food/" .. dish.name
local i = self.info[key]
local rx, ry = i[1] / self.K, i[2] / self.K
if dish.eaten_at then
local e = f - dish.eaten_at
local pkey = key .. "_plate"
local pi = self.info[pkey]
local px, py = pi[1] / self.K, pi[2] / self.K
if e < 15 then
self:tl(pkey, px, py)
local fx, fy = FRONT[dish.name][1], FRONT[dish.name][2]
self:tl(key, fx, fy, { fade = 1 - e / 15 })
elseif e < 37 then
local w, h = self:size(pkey)
local k = e - 15
self:ctr(pkey, px + w / 2, py + h / 2 - 27 * k, { rot = 8.2 * k })
end
return
end
if dish.front_at then
local e = f - dish.front_at
local fx, fy = FRONT[dish.name][1], FRONT[dish.name][2]
local p = clamp(e / 16, 0, 1)
local x = lerp(rx, fx, p * p * (3 - 2 * p))
local y = lerp(ry, fy, ease_out(p)) - 12 * math.sin(math.pi * p)
if dish.shake_at and f - dish.shake_at < 12 then
y = y - 5 * math.sin(math.pi * (f - dish.shake_at) / 12)
end
self:tl(key, x, y)
return
end
local e = f - DISHES_AT
if e < 45 then
self:tl(key, rx, ry - DISH_FALL + (DISH_FALL + 16) * ease_in(e / 45),
{ fade = 0.05 + 0.95 * ease_in(e / 56) })
elseif e < 56 then
self:tl(key, rx, lerp(ry + 16, ry, ease_out((e - 45) / 11)), { fade = 0.05 + 0.95 * ease_in(e / 56) })
else
self:tl(key, rx, ry)
end
end
function RetryGame:draw_dishes()
local active
for i, dish in ipairs(self.dishes) do
if dish.front_at and not dish.eaten_at then active = i else self:draw_dish(dish) end
end
if active then self:draw_dish(self.dishes[active]) end
end
function RetryGame:draw_timer()
local f = self.f
if f < READY_AT or (self.text_at and f >= self.text_at) then return end
local e = f - READY_AT
if e < 31 then
local p = ease_out(e / 31)
self:ctr("timer/digits", CX, 413, { s = lerp(4, 1, p), fade = p })
return
end
local _, dh = self:size("timer/digits")
if f < END_AT or (self.result and self.result_at < END_AT) then
local now = self.result and math.min(f, self.result_at) or f
local left = math.max(1, math.ceil((END_AT - math.max(now, GO_AT)) / 60))
local since = now < GO_AT and -1 or (now - GO_AT) % 60
local sx, sy = 1, 1
if left == 5 then sx, sy = digit_pop(since, 1, 1.1) else sx, sy = digit_pop(since, 1.6, 1.8) end
self:ctr("timer/digits", CX, 457 - dh * sy / 2, { frame = 5 - left, sx = sx, sy = sy })
return
end
local _, th = self:size("timer/time_up")
local sx, sy = digit_pop(f - END_AT, 1.6, 1.8)
self:ctr("timer/time_up", CX, 465 - th * sy / 2, { sx = sx, sy = sy })
end
function RetryGame:draw_text()
local f = self.f
if f >= DISHES_AT and f < RULE_OUT_AT + 34 then
local e = f - DISHES_AT
local s, a = pop_scale(e, true)
if f >= RULE_OUT_AT then
local d = f - RULE_OUT_AT
s = d < 10 and lerp(1, 1.5, ease_out(d / 10)) or lerp(1.5, 0, ease_in((d - 10) / 24))
end
self:ctr("callout/rule", CX, 222, { s = s, fade = a })
end
if f >= READY_AT and f < GO_AT then
local s, a = pop_scale(f - READY_AT, false)
self:ctr("callout/ready", CX, 232, { s = s, fade = a })
end
if f >= GO_AT and f < GO_AT + 54 then
local e = f - GO_AT
local s, a = pop_scale(e, true)
if e >= 38 then
local d = e - 38
s = d < 5 and lerp(1, 1.5, d / 5) or lerp(1.5, 0, (d - 5) / 11)
a = d < 5 and 1 or 1 - (d - 5) / 11
end
self:ctr("callout/go", CX, 220, { s = s, fade = a })
end
local mash_end = self.result and math.min(self.result_at, END_AT) or END_AT
if f >= GO_AT + 55 and f < mash_end + 30 then
local top, sy, a = -8, 1, 1
local e = f - (GO_AT + 55)
if e < 23 then
local p = ease_in(e / 23)
top, sy, a = lerp(-96, 22, p), lerp(0.096, 1, p), p
elseif e < 29 then
top = lerp(22, -8, ease_out((e - 23) / 6))
end
if f >= mash_end then
local d = f - mash_end
if d < 7 then
top = lerp(-8, 22, d / 7)
else
local p = 1 - ease_out((d - 7) / 23)
top, sy, a = lerp(-96, 22, p), lerp(0.096, 1, p), p
end
end
self:tl("callout/mash", CX - self:size("callout/mash") / 2, top, { sy = sy, fade = a })
end
if self.text_at and f >= self.text_at then
local s, a = pop_scale(f - self.text_at, true)
if self.result == "success" then
self:ctr("callout/success", CX, 242, { s = s, fade = a })
else
self:ctr("callout/failure", CX, 232, { s = s, fade = a })
end
end
end
function RetryGame:draw_back()
self:draw_background()
self:draw_don()
self:draw_dishes()
end
function RetryGame:draw_front()
self:draw_timer()
self:draw_text()
end
function RetryGame:draw()
self:draw_back()
self:draw_front()
end