-- YataiDONNantoka gameplay background: taikonantoka's Play/Bg, Dancer, Chara, Chibi, -- Drapery and Load layers (Files/Theme/Original/Play, 640x480, drawn 1:1). -- Numbers and timings come from dispconf.ini [演奏], the *.ini files next to the art and -- the decompiled play loop sub_40F6D0 / sub_422330 / sub_41CEB0 -- see -- Graphics/background/MAPPING_bg.md for the source of every constant. -- -- Time bases (taikonantoka): -- ms : play-screen milliseconds (dancer-bg NORMAL set, upper-bg scroll, fades) -- clk : beat clock, 3600 units per beat, follows BPM changes (dbl_162B918) -- The engine hands the background no GOGO flag and no difficulty; see MAPPING_bg.md -- ("engine gaps") for what that leaves out. -- Round 2: balloon burst from the engine's "balloon_pop" sound, balloon fail after the -- 1 s no-hit timeout, and the Play/Load/bg_end wipe when the song audio ("song") stops -- (continued over the engine's result transition by Scripts/result/result_transition.lua -- through the shared global NK_PLAY_WIPE_MS). local SCR = "background" local BEAT = 3600 -- Resolution independence: every screen-space number in this file (positions, distances, -- amplitudes, px/s speeds) is in taikonantoka's 640x480 pixels and is multiplied by -- K = screen width / 640 -- at the constant tables right below them, or inline as "* K". -- A skin reusing this script at 960x720 ships the art 1.5x, so K = 1.5. Texture sizes -- (t.w / t.h) are already screen pixels and are never scaled; times, alphas and frame math -- are unchanged. K is the integer 1 at 640 wide, so the native skin keeps exactly the same -- (integer) arithmetic. local K = tex.get_screen_width() / 640 K = math.tointeger(K) or K local SW, SH = 640 * K, 480 * K -- dispconf.ini [演奏] local CFG = { character_x = 86, character_y = 62, character_balloon_x = 125, character_balloon_y = 129, balloon_x = 247, balloon_y = 150, balloon_hit_x = 249, balloon_hit_y = 159, bubble_x = 207.5, bubble_y = 64, bubble_num_y = 58.8, bubble_num_w = 22, note_y = 156, } for k, v in pairs(CFG) do CFG[k] = v * K end -- Taiko 14 dancers (enso_parts.bin ODORIKYARA01-05): anchors left to right, joining in the order of -- taikonantoka's dancer.ini (centre, then outwards) as the gauge rises; dance loops are 40 swg frames a beat local DANCER_X, DANCER_Y, DANCER_JOIN = { 60, 190, 320, 450, 580 }, 436, { 3, 2, 4, 1, 5 } local DANCE_FPB, JUMP_MS = 40, 80 * 1000 / 60 -- Taiko 14 chibi (CHIBIKYARA at y -32): hop in over swg frames 0-19 (the miss chibi glides in), then glide right -- through a 2-beat loop (40 swg frames a beat) of each set's hand-written hop / bob / sway / spin: y is the sprite -- centre (swg px), then rotation and x / y scale; the miss chibi's motion takes swg frames local CHIBI_DY, CHIBI_FPB, TAU = -32, 40, 2 * math.pi local function hop(amp, n, p) return -amp * math.abs(math.sin(math.pi * n * p)) end local CHIBI_MOTION = { TSURU = function(p) return 100.6 + 10 * math.cos(TAU * p) end, DARUMA = function(p) return 117, 360 * p end, DARUMA2 = function(p) return 116.7 + hop(20, 2, p) end, WATAGASHI = function(p) local squash = 1 - 0.35 * math.max(0, math.cos(2 * TAU * (p - 0.15))) ^ 6 return 107 + 10 * math.sin(TAU * p), 6 - 21 * math.cos(2 * TAU * p), squash, squash end, HIYOKO = function(p) return 108.3 + hop(10, 4, p) end, HIYOKO2 = function(p) return 108 + hop(28, 1, p) end, SUZUDON = function(p) return 107.3 + hop(20, 2, p) end, MIZUMARIKO = function() return 104.5 end, MIZUMARIKO2 = function(p) return 122 + hop(45, 2, p) end, KENDAMA = function(p) return 113.6 + hop(50, 1, p) end, CHOUCHIN = function(p) return 120 + hop(33, 2, p) end, TAKOYAKI = function(p) return 124 + hop(48, 2, p) end, BARU_N = function(p, kind) local low = kind == "balloon_01" or kind == "balloon_04" return (low and 95 or 85) + 7 * math.cos(2 * TAU * p), -10 * math.sin(TAU * p) end, KINGYO = function(p, kind) if kind == "kin_03" or kind == "kin_04" then return 104.3, 0, 1 - 0.2 * math.sin(TAU * p) end return 81.3 + 10 * math.cos(2 * TAU * p) end, -- collab chibi: a plain 2-hop bob DEFAULT = function(p) return 112 + hop(20, 2, p) end, MISS = function(f) if f < 40 then return 81 end return 80 + 18 * math.min(1, (f - 40) / 20) * math.cos(TAU * (f - 84) / 40) end, } local P2_BALLOON_DY = 30 local P2_MIRROR = 475 -- 2P HUD: 1P y -> 475 - y (640 px; the 2P lane is the 1P lane mirrored) local SUBSETS = { "t14_title", "t14_daibg", "t14_chibi_miss", "nk_load", "nk_dan", "nk_bubble", "t14_course", "t14_bachio" } local function rad(deg) return deg * math.pi / 180 end local function trunc(v) if v >= 0 then return math.floor(v) else return math.ceil(v) end end -- C remainder (sign of the dividend) local function cmod(a, b) return math.fmod(a, b) end local NEVER = 1e9 local STAGES = require("background.t14_stages") local DANCERS = require("background.t14_dancers") local BACHIO = require("background.t14_bachio") local MASCOT = require("background.t14_mascot") local CHIBIS = require("background.t14_chibi") local COLLABS = require("background.t14_collabs") --------------------------------------------------------------------------------------------- -- parent collab scenes that have no taikonantoka counterpart keep the parent's look. -- DAN and PRACTICE gameplay use the taikonantoka enso (Graphics/game/MAPPING_hud.md, -- "Practice / Dan"): the engine hands them this same Background with scene_preset "DAN" / -- "PRACTICE"; the practice overlay (large drums, pause buttons, progress bar) and the dan -- panels / dan gauge are engine draws on top and keep working. local PARENT_SCENES = {} -- the tutorial overlay (Scripts/game/tutorial_overlay.lua) draws the whole dojo scene local DojoBackground = {} DojoBackground.__index = DojoBackground local function noop() end for _, k in ipairs({ "update", "handle_good", "handle_ok", "handle_bad", "handle_drumroll", "handle_balloon", "handle_gauge", "draw_back", "draw_fore", "destroy" }) do DojoBackground[k] = noop end Background = {} Background.__index = Background -- sub -> name -> texture (two levels: a hit builds no key string) local TCACHE = {} local MISSING = {} local function T(sub, name) local by_sub = TCACHE[sub] if not by_sub then by_sub = {}; TCACHE[sub] = by_sub end local c = by_sub[name] if c then return (c ~= MISSING) and c or nil end local id = tex.get_texture(SCR .. "/" .. sub .. "/" .. name) local info = id and tex.get_texture_info(sub, name) if not (id and info) then by_sub[name] = MISSING; return nil end c = { id = id, w = info.width, h = info.height } by_sub[name] = c return c end -- top-left draw local BLIT_P = {} local function blit(t, x, y, alpha, blend) if not t then return end local p = BLIT_P p.x, p.y = x, y p.fade = (alpha and alpha < 255) and math.max(alpha, 0) / 255 or nil p.blend = blend or nil tex.draw_texture(t.id, p) end -- centred draw (taikonantoka sub_431B30 / sub_432490: top-left = centre - size/2) local function blit_c(t, cx, cy, alpha, blend) if not t then return end blit(t, cx - t.w / 2, cy - t.h / 2, alpha, blend) end function Background.new(player_num, bpm, scene_preset) if scene_preset == "TUTORIAL" then return setmetatable({}, DojoBackground) end local parent = scene_preset and PARENT_SCENES[scene_preset] if parent then local mod = require(parent[1]) local cls = (type(mod) == "table" and mod.new) and mod or ({ PRACTICE = PracticeBackground })[scene_preset] if cls then if parent[2] then return cls.new(player_num, bpm, parent[2], parent[3]) end return cls.new(player_num, bpm) end end local self = setmetatable({}, Background) NK_DAN_RED = nil -- set by handle_dan (t14_hud picks the gauge art by it) self.player_num = player_num self.is_2p = (player_num == 3) self.bpm = (bpm and bpm > 0) and bpm or 120 for _, s in ipairs(SUBSETS) do tex.load_folder(SCR, s) end self.mascot_subs = {} for side, on in pairs({ don = player_num ~= 2, katsu = player_num ~= 1 }) do if on then self.mascot_subs[#self.mascot_subs + 1] = "t14_mascot_" .. side tex.load_folder(SCR, "t14_mascot_" .. side) end end -- random picks, as the game does when config.ini forces none -- Taiko 14 DONHAIKEI (1P) / KATSUHAIKEI (2P): normal, miss and fever strips of one set local collab = COLLABS.for_preset(scene_preset) local function pick(v) if type(v) == "table" then return v[math.random(1, #v)] end return v end local up = collab and collab.upper or string.format("%02d", math.random(1, 12)) -- one folder per pick: loading all 96 upper strips / 24 galleries cost 143 MB of texture per song self.upper_subs = {} local function upper(side) local sub = side .. "_" .. up tex.load_folder(SCR, "t14_upper/" .. sub) self.upper_subs[#self.upper_subs + 1] = "t14_upper/" .. sub return { p1 = T(sub, "normal"), miss = T(sub, "miss"), clear = T(sub, "fever") } end if player_num ~= 2 then self.upper = upper("don") end if player_num ~= 1 then self.upper2 = upper("katsu") end self.stage = T("t14_daibg", collab and collab.lantern or "lantern_" .. math.random(1, 3)) self.gallery_n = not collab and math.random(1, 3) or nil local gallery = "gallery_" .. (collab and pick(collab.gallery) or self.gallery_n) self.gallery_sub = "t14_fever/" .. gallery tex.load_folder(SCR, self.gallery_sub) self.gallery = T(gallery, "gallery") -- the generic random picks skip the collab parts local function generic(all, owned) local ids = {} for id in pairs(all) do if id ~= "MISS" and not owned[id] then ids[#ids + 1] = id end end table.sort(ids) return ids[math.random(1, #ids)] end -- Taiko 14 dance stage (Scripts/background/t14_stages.lua), one of the twelve generic ones self.stage_id = collab and collab.stage or generic(STAGES, COLLABS.owned.stage) self.stage_set = "t14_stage_" .. self.stage_id tex.load_folder(SCR, self.stage_set) self.stage_fever, self.stage_flip_ms = false, -NEVER -- Taiko 14 dancer set (Scripts/background/t14_dancers.lua): a part with a slot takes it, the rest fill the -- anchors in turn local set = DANCERS[collab and pick(collab.dancers) or generic(DANCERS, COLLABS.owned.dancers)] self.dance_folder = set.folder tex.load_folder(SCR, set.folder) self.dancers = {} for k = 1, #DANCER_X do local part = set.parts[(k - 1) % #set.parts + 1] for _, p in ipairs(set.parts) do if p[4] == k - 1 then part = p end end self.dancers[k] = { key = part[1], lag = part[2] / DANCE_FPB, dy = part[3], dance = set.dancers[part[1]], on = false, since = -NEVER } end self.chibi_id = collab and collab.chibi or generic(CHIBIS, COLLABS.owned.chibi) tex.load_folder(SCR, CHIBIS[self.chibi_id].folder) self.mascot_side, self.mascot_side2 = "don", "katsu" -- 2P playing alone (top HUD): the blue upper background and the katsu there too if player_num == 2 then self.upper, self.mascot_side = self.upper2, "katsu" end self.start_ms = nil self.ms = 0 -- ms since the play screen started self.now = 0 -- engine frame ms self.clk = 0 -- beat clock self.last_now = nil -- gauge / states (sub_41CEB0) self.gauge = 0 -- 0..100 self.gauge_int = 0 self.clear_line = 80 -- 60/70/80 by course; refined when the engine reports a clear self.is_clear = false self.is_full = false self.state = 0 -- 0 normal 1 miss 2 clear 3 full self.prev_state = 0 self.t_miss = NEVER self.t_clear = NEVER self.pending_hit = false self.clear_since = nil -- CLEAR dancer-bg clock origin (ms) self.level_t = {} -- beat-clock stamp per integer gauge level (dbl_162BFE8) self.level_t[0] = 7200 - 2000 self.combo = 0 self.hop_ms = -NEVER -- 2P (is_2p): the bottom HUD's own upper-bg / Don state, driven by player 2's events only. -- The 1P state stays on self; both go through the same code via Background:ps(player_num). self.p2 = { state = 0, prev_state = 0, t_miss = NEVER, t_clear = NEVER, pending_hit = false, combo = 0, hop_ms = -NEVER, is_clear = false, balloon = 0, balloon_ms = -NEVER, balloon_hit = false, pop_prev = false, gogo = false, mascot = { mode = "idle", since = -NEVER, steps = {} }, bdig = {} } self.balloon = 0 -- dword_8F9C8C: 1..6 rolling, 9 burst, 10 fail self.balloon_ms = -NEVER -- dbl_162B2F0 self.balloon_hit = false -- a balloon hit arrived since the last update self.pop_prev = false -- "balloon_pop" was playing at the previous balloon hit self.gogo, self.mascot, self.bdig = false, { mode = "idle", since = -NEVER, steps = {} }, {} self.wipe_ms = nil -- Play/Load/bg_end start (engine frame ms) self.end_bg = T("nk_load", "bg_end") NK_PLAY_WIPE_MS = nil self.chibis = {} self.gallery_on, self.gallery_off = nil, nil self.song_end_ms = nil return self end -- Quick restart (F1): the engine rebuilds the players but keeps this background object, so its -- own play state (combo, Don / upper-bg states, balloons, gauge) would carry over. A restart plays -- "restart"; a new play of it (audio.play_count, else the sound's rising edge) means start over. function NK_RESTARTED(st) if audio.play_count then local n = audio.play_count("restart") local hit = st.restart_n ~= nil and n > st.restart_n st.restart_n = n return hit end local on = audio.is_sound_playing("restart") local hit = on and not st.restart_on st.restart_on = on return hit end -- the per-play state of Background.new (textures and random picks stay) function Background:reset_play() self.start_ms, self.ms, self.now, self.clk, self.last_now = nil, 0, 0, 0, nil self.gauge, self.gauge_int, self.clear_line = 0, 0, 80 self.is_clear, self.is_full = false, false self.state, self.prev_state, self.t_miss, self.t_clear = 0, 0, NEVER, NEVER self.pending_hit, self.clear_since = false, nil self.level_t = { [0] = 7200 - 2000 } self.combo, self.hop_ms = 0, -NEVER self.p2 = { state = 0, prev_state = 0, t_miss = NEVER, t_clear = NEVER, pending_hit = false, combo = 0, hop_ms = -NEVER, is_clear = false, balloon = 0, balloon_ms = -NEVER, balloon_hit = false, pop_prev = false, gogo = false, mascot = { mode = "idle", since = -NEVER, steps = {} }, bdig = {} } self.balloon, self.balloon_ms, self.balloon_hit, self.pop_prev = 0, -NEVER, false, false self.gogo, self.mascot, self.bdig = false, { mode = "idle", since = -NEVER, steps = {} }, {} self.wipe_ms = nil NK_PLAY_WIPE_MS = nil self.chibis, self.gallery_on, self.gallery_off, self.song_end_ms = {}, nil, nil, nil self.bachio_combo_ms = nil for _, d in ipairs(self.dancers) do d.on, d.since = false, -NEVER end end --------------------------------------------------------------------------------------------- function Background:update(current_ms, bpm) self.restart_st = self.restart_st or {} if NK_RESTARTED(self.restart_st) then self:reset_play() end if bpm and bpm > 0 then self.bpm = bpm end if not self.start_ms then self.start_ms = current_ms end if self.last_now then local dt = current_ms - self.last_now if dt > 0 then self.clk = self.clk + dt * self.bpm / 60000 * BEAT end end self.last_now = current_ms self.now = current_ms self.ms = current_ms - self.start_ms -- chibi lifetime: 6 beats, or once off the right edge local keep = {} for _, c in ipairs(self.chibis) do if self.clk - c.clk < 21600 then keep[#keep + 1] = c end end self.chibis = keep self:update_balloon(self) if self.is_2p then self:update_balloon(self.p2) end -- Play/Load/bg_end: state 9 of the play loop starts when the BGM stops playing -- (IDirectSoundBuffer::GetStatus, sub_40F6D0 ~L11774). Polled only after the last note. if not self.wipe_ms and self.song_end_ms and not audio.is_sound_playing("song") then self.wipe_ms = current_ms if not NK_PLAY_WIPE_MS then NK_PLAY_WIPE_MS = current_ms end end end -- per-player state: self (1P, and the only player outside 2P) or self.p2 function Background:ps(player_num) if self.is_2p and player_num == 2 then return self.p2 end return self end -- balloon burst: the engine plays "balloon_pop" in the frame of the bursting hit -- (Player::check_balloon); a rising edge right after a balloon hit = burst (state 9). -- s = the player's state (self or self.p2): each player has its own balloon. function Background:update_balloon(s) if s.balloon_hit then s.balloon_hit = false local pop = audio.is_sound_playing("balloon_pop") if pop and not s.pop_prev and s.balloon >= 1 and s.balloon <= 6 then s.balloon = 9 -- timed from the bursting hit (dbl_162B2F0) end s.pop_prev = pop end local e = self.now - s.balloon_ms if s.balloon >= 1 and s.balloon <= 6 and e > 1000 then -- fallback for an engine without handle_balloon_end: 1 s without a hit counts as the -- balloon ending unburst s.balloon_last = s.balloon s.balloon = 10; s.balloon_ms = self.now elseif s.balloon == 9 and e >= 340 then s.balloon = 0 elseif s.balloon == 10 and e > 420 then s.balloon = 0 end end local function hit(self, player_num) local s = self:ps(player_num) s.symbol_hit_ms = self.now -- [YataiDON14] the difficulty symbol's hit glow s.pending_hit = true s.combo = s.combo + 1 if s.combo % 10 == 0 then s.hop_ms = self.now end if s == self and s.combo % 100 == 0 then self.bachio_combo_ms = self.now end if s == self then self:add_chibi(false) end -- chibis belong to the 1P HUD end function Background:handle_good(player_num) hit(self, player_num) end function Background:handle_ok(player_num) hit(self, player_num) end function Background:handle_bad(player_num) local s = self:ps(player_num) s.combo = 0 s.hop_ms = -NEVER if s.state ~= 1 then s.t_miss = self.ms s.prev_state = s.state s.state = 1 end if s == self then self:add_chibi(true) end end function Background:handle_drumroll(player_num) end function Background:handle_gogo(player_num, is_gogo) self:ps(player_num).gogo = is_gogo and true or false end function Background:handle_balloon(player_num, remaining) -- dword_8F9C8C: first hit 1, +1 per hit, capped at 6 local s = self:ps(player_num) s.balloon_left = remaining -- hits left (engine 24f8d9b; nil / -1 = not known: no bubble) if s.balloon == 0 or s.balloon >= 9 then s.balloon = 1 else s.balloon = math.min(s.balloon + 1, 6) end s.balloon_ms = self.now s.balloon_hit = true end -- the balloon reached its end note (8) unburst: the Don lets go right away (fail, as the 1 s -- timeout above), not up to a second later function Background:handle_balloon_end(player_num) local s = self:ps(player_num) if s.balloon >= 1 and s.balloon <= 6 then s.balloon_last = s.balloon s.balloon = 10; s.balloon_ms = self.now end s.balloon_left = nil end -- kusudama hits (the engine's handle_kusudama; without it they came as handle_balloon): the chara -- blows up a balloon only for balloon notes, never for a kusudama function Background:handle_kusudama(player_num) end function Background:handle_song_end(player_num, good, ok, bad, total) self.song_end_ms = self.now end -- DAN: the player has no gauge (game_dan.cpp resets it), so handle_gauge never comes; the -- dan gauge arrives with handle_dan (DanGameScreen::push_dan_state, every frame) and drives -- the dancers / upper-bg states the same way. Clear = the "gauge" exam's red value (80 when -- the course has none). Called on the object, so t14_hud's handle_gauge (chained onto it) gets -- the value too and draws taikonantoka's soul gauge at the normal-play position; the engine's -- own dan gauge is moved off-screen in Graphics/game/gauge_dan. function Background:handle_dan(player_num, st) if type(st) ~= "table" then return end local g = tonumber(st.gauge) or 0 local red = 80 if type(st.exams) == "table" then for _, row in ipairs(st.exams) do if type(row) == "table" and row.type == "gauge" and tonumber(row.red) and row.red > 0 then red = row.red; break end end end NK_DAN_RED = red self:handle_gauge(1, g / 100, g >= red, g >= 100) -- exam rows the engine will draw (draw_dan_info: gauge exams skipped, at most 3) local rows = 0 if type(st.exams) == "table" then for _, row in ipairs(st.exams) do if type(row) == "table" and row.type ~= "gauge" then rows = rows + 1 end end end self.dan_rows = math.min(rows, 3) end -- Dan exam panel: the parent's (PyTaikoGreen) dan background under the whole lower half, drawn at -- the end of draw_back, i.e. right before DanGameScreen::draw_dan_info: -- nk_dan/wall = background/collab/dan/bg_normal/bg_0 with its notice board painted out (vertical -- stripes only, so it is stretched from the song-title bar (y 255) to the bottom) -- nk_dan/footer = background/collab/dan/footer/0 (blue band), y 448..480 -- nk_dan/remaining_box = that notice board (bg_0 15..282 x 103..304, halved), under "残り音符数". -- Layout (Graphics/game/dan_info + skin_config dan_select_exam_info / dan_game_hori_name): the three exam -- rows share y 255..448 evenly (tops 263.5 / 327.5 / 391.5, step 64); the rank plate + board group -- (150 high) is centred in the same span. local DAN_PANEL = { top = 255, footer_y = 448, box_x = 6.5, box_y = 323.5 } function Background:draw_dan_panel() local P = DAN_PANEL local wall = T("nk_dan", "wall") if wall then local h = (480 - P.top) * K tex.draw_texture(wall.id, { x = 0, y = P.top * K, x2 = SW - wall.w, y2 = h - wall.h }) end blit(T("nk_dan", "footer"), 0, P.footer_y * K) blit(T("nk_dan", "remaining_box"), P.box_x * K, P.box_y * K) end function Background:add_chibi(bad) local id = bad and "MISS" or self.chibi_id local set = CHIBIS[id] local kind = set.pick[math.random(1, #set.pick)] if #self.chibis >= 100 then table.remove(self.chibis, 1) end self.chibis[#self.chibis + 1] = { id = id, folder = set.folder, kind = kind, loop = set.kinds[kind], clk = self.clk } end -- upper-bg state machine (sub_41CEB0, Great/Good branch) on a per-player state s local function upper_state(s, ms, is_clear, was_clear, is_rainbow) if s.pending_hit then s.pending_hit = false if s.state == 1 then s.t_miss = ms end if is_rainbow and s.state ~= 3 then s.prev_state = s.state; s.state = 3 elseif is_clear and s.state < 2 then s.prev_state = s.state; s.state = 2 if not was_clear then s.t_clear = ms end elseif not is_clear and s.state == 1 then s.prev_state = 1; s.state = 0; s.t_clear = NEVER end end if is_clear and not was_clear and s.state >= 2 and s.t_clear == NEVER then s.t_clear = ms end end function Background:handle_gauge(player_num, progress, is_clear, is_rainbow) if self.is_2p and player_num ~= 1 then if player_num == 2 then local s = self.p2 upper_state(s, self.ms, is_clear, s.is_clear, is_rainbow) s.is_clear = is_clear end return end local g = math.max(0, math.min(100, progress * 100)) local gi = math.floor(g + 1e-6) local was_clear = self.is_clear if is_clear and not was_clear then -- the engine's norma is 60/70/80 % like taikonantoka's dword_8FA188 if gi < 70 then self.clear_line = 60 elseif gi < 80 then self.clear_line = 70 else self.clear_line = 80 end elseif not is_clear and gi >= self.clear_line - 10 and self.clear_line < 80 then self.clear_line = math.min(80, math.floor(gi / 10) * 10 + 10) end -- per-level beat-clock stamps (thread code C 12610) if gi > self.gauge_int then for i = self.gauge_int + 1, gi do self.level_t[i] = self.clk end elseif gi < self.gauge_int then for i = gi, self.gauge_int - 1 do self.level_t[i] = self.clk end end -- CLEAR dancer-bg clock: ms since the gauge last reached the clear line if is_clear and not was_clear then self.clear_since = self.ms end if not is_clear then self.clear_since = nil end upper_state(self, self.ms, is_clear, was_clear, is_rainbow) self.gauge = g self.gauge_int = gi self.is_clear = is_clear self.is_full = is_rainbow end --------------------------------------------------------------------------------------------- local STAGE_Y, STAGE_FADE, FRAME_MS = 255 * K, 500, 1000 / 60 local function swing(v, f, P) if type(v) ~= "table" then return v end return (v[1] + v[2]) / 2 + (v[2] - v[1]) / 2 * math.cos(2 * math.pi * (f - v[3]) / P) end local STAGE_P, ORIGIN = {}, {} function Background:draw_stage_layers(rows, f, alpha) local p = STAGE_P for _, l in ipairs(rows) do local t = T(self.stage_set, l.tex) if t then p.x2, p.y2, p.origin, p.rotation, p.mirror = nil, nil, nil, nil, nil p.fade = alpha < 1 and alpha or nil if l.kind == "base" then p.x, p.y = l.x * K, STAGE_Y + l.y * K tex.draw_texture(t.id, p) elseif l.kind == "scroll" then local span = l.span * K local x = (l.v * K * f) % span - span p.y = STAGE_Y + l.y * K while x < SW do p.x = x tex.draw_texture(t.id, p) x = x + span end else local P = l.period local sx, sy = swing(l.sx, f, P), swing(l.sy, f, P) local w, h = t.w * sx, t.h * sy local rot = swing(l.rot, f, P) + (l.spin or 0) * f local a = swing(l.a, f, P) * alpha if l.on then a = a * l.on[math.floor(f) % P + 1] end if a > 0.004 then p.x, p.y = swing(l.x, f, P) * K, STAGE_Y + swing(l.y, f, P) * K p.x2, p.y2 = w - t.w, h - t.h ORIGIN[1], ORIGIN[2] = w / 2, h / 2 p.origin, p.rotation = ORIGIN, rot p.mirror = l.mirror and "horizontal" or nil p.fade = a < 1 and a or nil tex.draw_texture(t.id, p) end end end end end -- the dance stage: normal, or fever while the gauge is in the clear zone (cross-fade over 0.5 s) function Background:draw_dancer_bg() local st = STAGES[self.stage_id] if not st then return end local fever = self.clear_since ~= nil if fever ~= self.stage_fever then self.stage_fever, self.stage_flip_ms = fever, self.ms end local f = self.ms / FRAME_MS local p = math.min(1, (self.ms - self.stage_flip_ms) / STAGE_FADE) local from, to = fever and st.normal or st.fever, fever and st.fever or st.normal if p < 1 then self:draw_stage_layers(from, f, 1) end self:draw_stage_layers(to, f, p) end -- Taiko 14 upper background: the strips scroll 0.8 swg px a frame and loop every 256; the fever (clear) and miss -- layers cross-fade over 10 frames local UP_PERIOD, UP_SPEED, UP_FADE = 256 * K, 48 * K, 167 function Background:draw_upper(y0, u, s) y0 = y0 or 0 u = u or self.upper s = s or self if not u.p1 then return end local t = self.ms local x = -((t * UP_SPEED / 1000) % UP_PERIOD) blit(u.p1, x, y0) local dc = t - s.t_clear if u.clear and dc >= 0 then blit(u.clear, x, y0, (s.state >= 2 and dc < UP_FADE) and trunc(dc / UP_FADE * 255) or nil) end local dm = t - s.t_miss if u.miss and dm >= 0 then if s.state == 1 then blit(u.miss, x, y0, dm < UP_FADE and trunc(dm / UP_FADE * 255) or nil) elseif s.prev_state == 1 and dm < UP_FADE then blit(u.miss, x, y0, trunc(255 - dm / UP_FADE * 255)) end end end local function routine_frame(order, f) for i = 2, #order, 2 do f = f - order[i] if f < 0 then return order[i - 1] end end end -- Taiko 14 mascot (DONKATSU don_01 / katsu_01, GEKIDON): the Don's mode follows the gauge, misses and gogo time. -- A mode change plays the swg's transition clips, then the mode loops on the beat (40 swg frames a beat). local MODE_LOOP = { -- routine, loop start, loop length (swg frames) idle = { "idle", 0, 160 }, clear = { "clear_up", 40, 39 }, full = { "full_up", 120, 80 }, gogo = { "gogo", 0, 80 }, full_gogo = { "full_gogo", 40, 80 }, miss = { "miss", 0, 39 }, } local MODE_INTRO = { clear = { "clear_up", 40 }, full = { "full_up", 120 }, full_gogo = { "full_gogo", 40 } } local MODE_LEAVE = { clear = "clear_down", full = "clear_down", gogo = "gogo_end", full_gogo = "full_gogo_end", miss = "miss_end" } local BALLOON_FRAME_MS = 1000 / 60 local ROUTINE_LEN = setmetatable({}, { __mode = "k" }) local function routine_len(order) local n = ROUTINE_LEN[order] if not n then n = 0 for i = 2, #order, 2 do n = n + order[i] end ROUTINE_LEN[order] = n end return n end local function mascot_steps(old, new) local steps = {} if MODE_LEAVE[old] and (new == "idle" or new == "clear") then steps[#steps + 1] = { MODE_LEAVE[old] } end local intro = MODE_INTRO[new] if intro and (new ~= "clear" or old == "idle") then steps[#steps + 1] = intro end return steps end function Background:mascot_frame(s, side) local m = s.mascot local mode = s.state == 1 and "miss" or s.state == 3 and (s.gogo and "full_gogo" or "full") or s.gogo and "gogo" or s.state == 2 and "clear" or "idle" if m.mode ~= mode then m = { mode = mode, since = self.now, steps = mascot_steps(m.mode, mode) } s.mascot = m end local routines = MASCOT[side] local f = (self.now - m.since) * 60 / 1000 local hop = (self.now - s.hop_ms) * 60 / 1000 if mode ~= "miss" and hop < 40 then local key = (mode == "full" or mode == "full_gogo") and "full_combo" or "combo" return key, routine_frame(routines[key], hop) end for _, step in ipairs(m.steps) do local order = routines[step[1]] local len = step[2] or routine_len(order) if f < len then return step[1], routine_frame(order, f) end f = f - len end local loop = MODE_LOOP[mode] return loop[1], routine_frame(routines[loop[1]], loop[2] + (self.clk / BEAT * 40) % loop[3]) end -- Play/Chara: cy_override moves the Don to the 2P HUD (it is not flipped) function Background:draw_chara(cy_override, side, s) s = s or self if s.balloon > 0 then return end side = side or self.mascot_side local key, frame = self:mascot_frame(s, side) local t = T("t14_mascot_" .. side, key) if not t or not frame then return end tex.draw_texture(t.id, { frame = frame, y = cy_override and cy_override - CFG.character_y or 0, x2 = t.w * (K - 1), y2 = t.h * (K - 1) }) end -- balloon-roll Don (GEKIDON): stage 1..6 per hit (15 swg frames each), burst (9) and miss (10) clips -- s / side: the player's state and art; Y maps a 1P y to this player's (2P: mirrored about y 237.5) function Background:draw_balloon_chara(s, side, Y) s = s or self side = side or self.mascot_side Y = Y or function(y) return y end if s.balloon <= 0 then return end local dy = Y(CFG.balloon_y) - CFG.balloon_y local e = self.now - s.balloon_ms local f = e / BALLOON_FRAME_MS local key if s.balloon == 9 then key = "burst" elseif s.balloon == 10 then key = "miss" .. (s.balloon_last or 1) else key, f = "stage" .. s.balloon, math.min(f, 14) end local order = MASCOT[side].balloon[key] local t = T("t14_mascot_" .. side, "balloon_" .. key) if t then tex.draw_texture(t.id, { frame = routine_frame(order, f) or order[#order - 1], y = dy, x2 = t.w * (K - 1), y2 = t.h * (K - 1) }) end if s.balloon <= 6 then self:draw_balloon_bubble(s, side, dy) end end -- hits left on the bubble: right-aligned digits (25 swg px apart), a changed digit stretches up 7 swg px and settles -- over 9 swg frames local DIGIT_X, DIGIT_Y, DIGIT_STEP, DIGIT_H = 214, 40, 25, 32 function Background:draw_balloon_bubble(s, side, dy) local left = s.balloon_left if not left or left < 0 then return end blit(T("t14_mascot_" .. side, "balloon_bubble"), 0, dy) local glyph = T("t14_mascot_" .. side, "balloon_digit") if not glyph then return end local str = tostring(left) for i = 1, #str do local k = #str - i local v = str:byte(i) - 48 local d = s.bdig[k] if not d or d.v ~= v then d = { v = v, ms = self.now } s.bdig[k] = d end local f = (self.now - d.ms) / BALLOON_FRAME_MS local up = f < 2 and 3.6 * f or f < 9 and 7.2 * (9 - f) / 7 or 0 tex.draw_texture(glyph.id, { frame = v, x = (DIGIT_X - DIGIT_STEP * k) * K, y = (DIGIT_Y - up) * K + dy, y2 = up * K }) end end -- the in / out hops: up from behind the stage, peak 60 px over the anchor, land; out the other way down local function hop_in(p) if p >= 0.6 then return 0 end if p < 0.3 then return 120 - 180 * math.sin(p / 0.3 * math.pi / 2) end return -60 + 60 * ((p - 0.3) / 0.3) ^ 2 end local function hop_out(p) if p < 0.3 then return -60 * math.sin(p / 0.3 * math.pi / 2) end return -60 + 260 * ((p - 0.3) / 0.7) ^ 2 end local DANCE_LEN = setmetatable({}, { __mode = "k" }) local function dance_frame(dance, beat) local order = dance.order local len = DANCE_LEN[dance] if not len then len = 0 for i = 2, #order, 2 do len = len + order[i] end DANCE_LEN[dance] = len end local f = (beat / dance.beats % 1) * len for i = 2, #order, 2 do f = f - order[i] if f < 0 then return order[i - 1] end end return order[#order - 1] end -- dancer n of the join order shows from gauge level trunc(n * clear_line / 4), as taikonantoka's Play/Dancer local DANCER_P = {} function Background:draw_dancers() local beat = self.clk / BEAT for n, k in ipairs(DANCER_JOIN) do local d = self.dancers[k] local want = trunc((n - 1) * self.clear_line * 0.25) <= self.gauge_int if want ~= d.on then d.on, d.since = want, self.ms end local p = (self.ms - d.since) / JUMP_MS local hop = d.on and hop_in(p) or (p < 1 and hop_out(p)) or nil local t = hop and T(self.dance_folder, d.key) if t then local q = DANCER_P q.frame = dance_frame(d.dance, beat + d.lag) q.x, q.y = DANCER_X[k] * K, (DANCER_Y + d.dy + hop) * K q.x2, q.y2 = t.w * (K - 1), t.h * (K - 1) tex.draw_texture(t.id, q) end end end -- Taiko 14 lantern strip along the screen's bottom edge (DAIBG chochin_1p-3p, one picked at random) function Background:draw_stage() blit(self.stage, 0, 0) end -- Taiko 14 fever gallery (FI_BA_GYARARI_ fever_01-03, swg y below its rest): with the soul gauge full it rises over -- the next beat (swg frames 5-45), lands on every beat after (fever_02 jumps higher every other beat), and once the -- gauge drops it hops and falls from the next beat (frames 126-166) function Background:draw_gallery() local g = self.gallery if not g then return end local clk = self.clk if not self.gallery_on then if not self.is_full then return end self.gallery_on = math.ceil(clk / BEAT) * BEAT end local on = (clk - self.gallery_on) / BEAT if on < 0 and not self.is_full then self.gallery_on = nil; return end if not (self.is_full or self.gallery_off) then self.gallery_off = math.ceil(clk / BEAT) * BEAT end local off = self.gallery_off and (clk - self.gallery_off) / BEAT if on < 0 then return end local y if off and off >= 0 then local f, top = off * DANCE_FPB, (self.gallery_n == 2) and 0 or 20 if f < 9 then y = 44 - (44 - top) * math.sin(math.pi / 2 * f / 9) else y = top + (216 - top) * ((f - 9) / 29) ^ 2 end if f >= 40 then self.gallery_on, self.gallery_off = nil, nil; return end elseif on < 1 then local f = on * DANCE_FPB if f < 20 then y = 240 * (1 - f / 20) ^ 2 else y = 50 * (1 - math.cos(math.pi / 2 * (f - 20) / 20)) end else local amp = (self.gallery_n == 2 and math.floor(on) % 2 == 0) and 68 or 50 y = 50 - amp * math.sin(math.pi * (on % 1)) end blit(g, 0, y * K) end local CHIBI_P, CHIBI_ORIGIN = {}, {} function Background:draw_chibis() local p = CHIBI_P for _, c in ipairs(self.chibis) do local f = (self.clk - c.clk) / BEAT * CHIBI_FPB local x, y, rot, sx, sy, frame if c.id == "MISS" then x = 139 + 3.58 * f y = CHIBI_MOTION.MISS(f) frame = dance_frame(c.loop, f / CHIBI_FPB) elseif f < 20 then local q = f / 20 x = 137 + 107.5 * q y = 99 + ((CHIBI_MOTION[c.id] or CHIBI_MOTION.DEFAULT)(0, c.kind) - 99) * q - 36 * math.sin(math.pi * q) frame = c.loop.intro else x = 244.5 + 3.26 * (f - 20) y, rot, sx, sy = (CHIBI_MOTION[c.id] or CHIBI_MOTION.DEFAULT)((f - 20) / 80 % 1, c.kind) frame = dance_frame(c.loop, (f - 20) / CHIBI_FPB) end local t = T(c.folder, c.kind .. "_" .. frame) if t and (x * K - t.w) <= SW then local w, h = t.w * (sx or 1), t.h * (sy or 1) p.x, p.y = x * K, (y + CHIBI_DY) * K p.x2, p.y2 = w - t.w, h - t.h CHIBI_ORIGIN[1], CHIBI_ORIGIN[2] = w / 2, h / 2 p.origin, p.rotation = CHIBI_ORIGIN, rot or 0 tex.draw_texture(t.id, p) end end end --------------------------------------------------------------------------------------------- -- 2P (skin_config game_p2_y 231): 1P HUD / 1P lane (116..220) / title bar (220..255) / 2P lane -- (255..359) / 2P HUD (359..480) -- the 2P lane is the 1P lane mirrored about y 237.5 (y -> 475 - y). -- The 2P HUD gets the blue upper background and the blue Don (mirrored position, not flipped); the -- soul gauge / combo / roll are t14_hud's. local P2_HUD_Y = 359 local P2_LANE_EDGE_H = 4 function Background:draw_p2_hud() self:draw_upper(P2_HUD_Y * K, self.upper2, self.p2) self:draw_symbol(2, self.p2, (P2_MIRROR - 64) * K) -- [YataiDON14] the 2P difficulty symbol self:draw_chara((P2_MIRROR - 62) * K, self.mascot_side2, self.p2) -- CFG.character_y is already x K: 62 = dispconf tex.draw_rect(0, P2_HUD_Y * K, SW, P2_LANE_EDGE_H * K, 0, 0, 0, 255) end -- The Taiko 14 title band (enso_kyokumei_ac) under the 1P lane, drawn once here so the 2P lane does not get a -- second one; the song title, course and song number on it are Scripts/game/song_info.lua's. local SYMBOL_COURSE = { [0] = "easy", "normal", "hard", "oni", "dondaful" } local SYMBOL_GLOW1 = { 0, 0, .5, 1, .918, .832, .75, .668, .582, .5, .418, .332, .25, .168, .082, 0 } local SYMBOL_GLOW2 = { 0, 0, 0, 0, .5, 1, .801, .602, .398, .199, 0, 0, 0, 0, 0, 0 } -- Taiko 14 course mark (KO_SUMA_KU): the glows fade in and out over the base on each hit; ura shows ドンだフル function Background:draw_symbol(pn, s, cy) local c = type(NK_COURSE_BY_PLAYER) == "table" and NK_COURSE_BY_PLAYER[pn] local name = SYMBOL_COURSE[c or 3] or "oni" local base = T("t14_course", name .. "_base") if not base then return end local x, y = 97 * K, cy - base.h / 2 blit(base, x, y) if s.symbol_hit_ms then local f = trunc((self.now - s.symbol_hit_ms) * 60 / 1000) + 1 local a1, a2 = SYMBOL_GLOW1[f], SYMBOL_GLOW2[f] if a1 and a1 > 0 then blit(T("t14_course", name .. "_glow1"), x, y, trunc(a1 * 255)) end if a2 and a2 > 0 then blit(T("t14_course", name .. "_glow2"), x, y, trunc(a2 * 255)) end end end -- Taiko 14 bachio (enso/1PDON/bachio) on their drum at the stage's bottom right for the whole song: they rise in at -- the start, bob on the beat (4-beat loop), and juggle on every 100 combo (Scripts/background/t14_bachio.lua) local BACHIO_LOOP = { order = BACHIO.loop, beats = 4 } function Background:draw_bachio() local key, frame = "loop", nil local fc = self.bachio_combo_ms and (self.now - self.bachio_combo_ms) * 60 / 1000 if fc then frame = routine_frame(BACHIO.combo, fc) if frame then key = "combo" else self.bachio_combo_ms = nil end end if not frame then frame = routine_frame(BACHIO.start, self.ms * 60 / 1000) if frame then key = "start" else frame = dance_frame(BACHIO_LOOP, self.clk / BEAT) end end local t = T("t14_bachio", key) if t then tex.draw_texture(t.id, { frame = frame, x2 = t.w * (K - 1), y2 = t.h * (K - 1) }) end end function Background:draw_back() self:draw_dancer_bg() self:draw_upper() self:draw_symbol(1, self, 64 * K) -- [YataiDON14] under the chara self:draw_chara() if not self.is_2p then self:draw_dancers() end self:draw_stage() if not self.is_2p then self:draw_bachio() end if not self.is_2p then self:draw_gallery() end if self.is_2p then self:draw_p2_hud() end blit(T("t14_title", "title_band"), 0, 0) if self.dan_rows then self:draw_dan_panel() end end function Background:draw_fore() self:draw_chibis() self:draw_balloon_chara() if self.is_2p then self:draw_balloon_chara(self.p2, self.mascot_side2, function(y) return (P2_MIRROR + P2_BALLOON_DY) * K - y end) end -- The wipe is drawn by Scripts/result/result_transition.lua only: that layer is above the -- engine's song title (GameScreen::draw_overlay), this one is below it (user: no title on -- the transition). end -- Play/Load/bg_end.png (640x960): y = 480 - 0.96 d, d = ms since the BGM stopped, -- -480 from 1000 ms on (asm 0x41C229); the bottom half then covers the screen until the -- engine changes scene (result_transition.lua keeps drawing it above the HUD). function Background:draw_end_wipe() if not (self.wipe_ms and self.end_bg) then return end local d = self.now - self.wipe_ms blit(self.end_bg, 0, (d < 1000) and (SH - d * 0.96 * K) or -SH) end function Background:destroy() TCACHE = {} for _, s in ipairs(SUBSETS) do tex.unload_folder(SCR, s) end for _, s in ipairs(self.mascot_subs) do tex.unload_folder(SCR, s) end for _, s in ipairs(self.upper_subs) do tex.unload_folder(SCR, s) end if self.gallery_sub then tex.unload_folder(SCR, self.gallery_sub) end if self.stage_set then tex.unload_folder(SCR, self.stage_set) end if self.dance_folder then tex.unload_folder(SCR, self.dance_folder) end if self.chibi_id then tex.unload_folder(SCR, CHIBIS[self.chibi_id].folder) end end -- HUD module (Graphics/game/MAPPING_hud.md, round 2) do local ok, hud = pcall(require, "game.t14_hud"); if ok and type(hud) == "table" then hud.install(Background) end end