local K = tex.get_screen_width() / 640 local S = tex.get_screen_scale() local FRAME_MS = 1000 / 60 local START_X = 150 -- the arc starts on the judge circle: judge_x + this, + notes' own x -- bezier control and end (swg px from the judge circle): 1P flies up to the top gauge, 2P down to the bottom one local PATH = { [false] = { 163.6, -203.2, 443.3, -117.7 }, [true] = { 358, 244, 444, 139.1 } } local BURST_FRAMES = 20 local TRAIL = { first = 3, every = 2, count = 10, frames = 16, scale = 2 } local P2_RAINBOW_Y = 435 * S NoteArc = {} NoteArc.__index = NoteArc local function trunc(v) return v < 0 and math.ceil(v) or math.floor(v) end function NoteArc.new(note_tex_type, big, is_balloon, player_num, start_x, start_y) local self = setmetatable({}, NoteArc) self.big = big self.is_balloon = is_balloon self.p2 = player_num == 2 local p = PATH[self.p2] self.sx = start_x + START_X self.sy = start_y + tex.get_skin_config("game_notes").y self.cx, self.cy = self.sx + p[1] * K, self.sy + p[2] * K self.ex, self.ey = self.sx + p[3] * K, self.sy + p[4] * K self.t_note = tex.get_texture("game/notes/" .. note_tex_type) local info = tex.get_texture_info("notes", tostring(note_tex_type)) self.note_w, self.note_h, self.note_x = info.width, info.height, info.x and info.x[1] or 0 local katsu = note_tex_type == 2 or note_tex_type == 4 local fw = big and (katsu and "firework_katsu" or "firework") self.t_firework = fw and tex.get_texture("game/hit_effect/" .. fw) or nil self.firework_info = self.t_firework and tex.get_texture_info("hit_effect", fw) self.t_burst = { tex.get_texture("game/hit_effect/burst_1"), tex.get_texture("game/hit_effect/burst_2"), tex.get_texture("game/hit_effect/burst_3") } self.burst_info = { tex.get_texture_info("hit_effect", "burst_1"), tex.get_texture_info("hit_effect", "burst_2"), tex.get_texture_info("hit_effect", "burst_3") } self.t_rainbow = tex.get_texture("game/balloon/rainbow") if self.t_rainbow then self.rainbow_info = tex.get_texture_info("balloon", "rainbow") end -- the engine keeps the arc alive this many frames past the flight (burst, trail) self.firework_frames = BURST_FRAMES return self end function NoteArc:point(t) local ti = 1 - t return ti * ti * self.sx + 2 * ti * t * self.cx + t * t * self.ex, ti * ti * self.sy + 2 * ti * t * self.cy + t * t * self.ey end -- the note's centre for a top-left (x, y) function NoteArc:centre(x, y) return x + self.note_x + self.note_w / 2, y + self.note_h / 2 end function NoteArc:draw_rainbow(y, raw_progress) local w, h = self.rainbow_info.width, self.rainbow_info.height local trail_start = math.max(0, raw_progress - 0.5) local trail_end = math.min(raw_progress, 1) if trail_end <= trail_start then return end local crop_start = math.floor(trail_start * w + 0.5) local crop_w = math.floor(trail_end * w + 0.5) - crop_start if crop_w <= 0 then return end local y_pos = self.p2 and P2_RAINBOW_Y or 0 tex.draw_texture(self.t_rainbow, { x = crop_start, y = y + y_pos, x2 = -w + crop_w, src = { x = crop_start, y = 0, width = crop_w, height = self.p2 and -h or h }, }) end -- fireworks dropped along the path every 2 swg frames from frame 3, each playing its 16 frames at x2 function NoteArc:draw_trail(y, elapsed_ms, duration_ms) local info = self.firework_info for i = 0, TRAIL.count - 1 do local spawn = (TRAIL.first + TRAIL.every * i) * FRAME_MS local frame = math.floor((elapsed_ms - spawn) / FRAME_MS) if frame >= 0 and frame < TRAIL.frames then local cx, cy = self:centre(self:point(math.min(spawn / duration_ms, 1))) tex.draw_texture(self.t_firework, { frame = frame, center = true, scale = TRAIL.scale, blend = "additive", x = cx - info.width / 2, y = y + cy - info.height / 2 }) end end end -- arrival: a puff (2 frames), a ring of puffs (2 frames), then a big ring that turns 45 -> 90 deg and grows to -- full size by frame 14, turning on to 110 deg as it fades by frame 17; big notes' ring is 1.2x local function ease_out(t) return 1 - (1 - t) * (1 - t) end function NoteArc:draw_burst(y, f) local cx, cy = self:centre(self.ex, self.ey) cy = cy + y local i, s, rot, a = 3, 1, 0, 1 if f < 2 then i = 1 elseif f < 4 then i = 2 elseif f < 14 then local t = ease_out((f - 4) / 10) s, rot = .5 + .5 * t, 45 + 45 * t elseif f < 17 then local t = (f - 14) / 5 s, rot, a = 1 + .1 * t, 90 + 20 * t, 1 - (f - 14) / 2.5 else return end if i < 3 then s = 1 end if self.big then s = s * 1.2 end local t, info = self.t_burst[i], self.burst_info[i] if not (t and info) or a <= 0 then return end local w, h = info.width * s, info.height * s tex.draw_texture(t, { x = cx, y = cy, origin = { w / 2, h / 2 }, rotation = rot, x2 = w - info.width, y2 = h - info.height, fade = a < 1 and a or nil }) end function NoteArc:draw(y, elapsed_ms, duration_ms) local progress = math.min(1, elapsed_ms / duration_ms) if self.is_balloon and self.t_rainbow then self:draw_rainbow(y, elapsed_ms / duration_ms) end if self.t_firework and self.firework_info then self:draw_trail(y, elapsed_ms, duration_ms) end if progress < 1 then local x, yy = self:point(progress) tex.draw_texture(self.t_note, { x = trunc(x), y = y + trunc(yy) }) return end -- at the gauge: the note brightens to white over 10 frames and fades over the next 10 under the burst local f = (elapsed_ms - duration_ms) / FRAME_MS local a = f < 10 and 1 or math.max(0, 1 - (f - 10) / 10) if a > 0 then local p = { x = trunc(self.ex), y = y + trunc(self.ey), fade = a < 1 and a or nil } tex.draw_texture(self.t_note, p) local w = math.min(1, f / 10) * a if w > 0 then tex.draw_texture(self.t_note, { x = p.x, y = p.y, fade = w, blend = "additive" }) end end self:draw_burst(y, f) end return NoteArc