Skip to content

The Event Showcase

Want to see what all of this looks like in one go? The Event Showcase is a complete song - two minutes, 140 BPM, intro to outro - where every single effect is an event file in the song's folder. 31 of them, plus 2 shaders. What moves the lanes is in .modchart files, the rest in .event files; an effect that does both is a pair with one name. Play it with the No Mod modifier and every lane effect stays out while the camera, texts and shaders still run.

Every big feature gets its own moment: texts and pictures, the callbacks, the HUD and the strum background, a whole modchart (lanes that jiggle, fly off the screen, scroll across it, turn upside down and ride a ring), the fight camera, the fighters (a dance, a death, a giant, swapping places), built-in effects and the song's own shaders. While it plays, a caption in the top left names each feature right as it starts.

And it's meant to be taken apart: the event files are commented, so open them up, read them, and copy whatever you like into your own songs.

Download the song (.zip)

Unzip it into your songs folder (.minecraft/MineFunkin/client/songs/) and play Event Showcase at a Speaker - against the dummy or a friend. That's where it shines: the camera and the fighters only exist in a fight. In practice at the Retro TV everything else still runs.

Power On: the title on the old TV

Opponent Echo: the strumline leans, the camera follows the singer

Build Up: the 3-2-1, the lanes spinning

The Drop with a shockwave: the fighters knocked back

Lane Lights: the strum background lit up

The dance: both fighters, the camera swung round, the words

Fake Death: the colour drained

Rise: a giant, a shockwave, the lanes coming back

Scroller: the lanes across the screen

Switcheroo: swapped places

Kick Hit and Logo Bump

Upside Down: the playfield turning, the world upright

Upside Down: turned over

Halo: a ring with depth

Power Off: the score on the old TV, just before it closes

The song, part by part

Part Bars What happens
Intro 1-4 The screen switches on like an old TV - a dot, a line, the picture - with the title on it. The playfield starts to drift.
Verse 1 5-12 Call and response. The camera follows whoever sings, your hits pop their lanes, your strumline leans toward the opponent's notes, the combo meter shouts at 25.
Verse 2 13-20 A spotlight follows the melody, then the lanes get kicked around on the drum pattern.
Build 21-24 Zoom, dark edges, shake and a 3-2-1. On the opponent's bar the lanes fly off the screen, then they spin.
Drop 25-32 An impact: a shockwave knocks both fighters back. The playfield punches on the kicks, the strum background lights up, another shockwave, the lanes hop in turns.
The dance 33-40 Both fighters stop their own animation and dance eight moves, mirrored. The camera swings round them; the words come in one by one.
Fake death 41-44 The opponent drops dead, the colour drains, the lanes fall off the screen. A heartbeat - then it rises as a giant and the lanes shoot back up.
Breakdown 45-48 The lanes spread across the whole screen and scroll sideways, wrapping round at the edges.
Rebuild 49-52 The fighters jump over each other and swap places; two lanes come from the other side.
Final drop 53-68 Every kick hits the picture, the logo bumps under the notes, the fighters swap back. The playfield turns upside down for four bars - the world stays upright - and back. Then a swap ping-pong.
Outro 69-72 The lanes ride a ring, then drop out of it. The live score - and the TV switches off.

Notice how the wildest moves (the lanes off the screen, the playfield turning over) only happen on bars where the opponent sings? That's on purpose - nobody has to play through them. And every effect keeps to its own property ("channel") or its own bars, so they stack without fighting each other - see strum[lane].

What each file shows

Looking for an example of something specific? Find it here, then open that file:

File Part of the song Shows
power_on.event intro a song shader (shaders/crt.fsh) driven by its four numbers: a dot, a line, the picture; the title on the "top" layer
caption.event every part a counter kept for the whole song, a newer caption cancelling an older one's slide-out
cam_sway.event from the intro on onFrame(dt), noise(), easing a variable by hand, reading shared hype
judge_glow.event + .modchart from verse 1 on onHit / onMiss, note.judgment / note.offset, a function that returns a value
cam_follow.event verse 1 on onHit / onOpponentHit easing camera.z / .x / .yaw toward whoever sings (fights)
opponent_echo.event + .modchart verse 1 onOpponentHit, lanes turned into directions, a vignette pulse
combo_meter.event the whole song a song script: no chart event, only onHit / onMiss and player.combo
spotlight.event + .modchart verse 2 onHit and onOpponentHit sharing one function, strum[lane].alpha per lane
jiggle.modchart verse 2, the drops a modchart's kick: wobbleX / wobbleY jolted on a drum pattern from onStep(n)
build_up.event build onStep patterns that speed up, a 3-2-1 scheduled in a for loop, writing shared hype
kade_sway.modchart build .x / .y from sin() every frame; "wild" takes tan(), so the lanes fly off the screen and come back
spin.modchart build, the end .angle from 360 to 0: once or every bar, counted from where the event sits
the_drop.event both drops an impact, kick / snare patterns in onBeat, hsv() colours, hud.angle
shockwave.event every impact a shader (shaders/shockwave.fsh) handed its start time; the fighters' pitch / squash / z
lane_lights.event drop the strum background (underlay.color / .alpha / .width) flaring on the beat
hop.modchart drops max(0, sin()) as a bouncing ball, isDown to hop toward the middle
dance_routine.event the dance animate = false, body parts, eight moves as functions, a mirror flag, fighter[i]
orbit_cam.event the dance camera.x / .y / .z / .yaw / .pitch together: circling the fighters
word_by_word.event the dance six parameters from the parts of one value, after() keeping each step, break
fake_death.event fake death opponent.pose = "death", fx.saturation draining the colour, the camera looking down
drop_out.event + .modchart fake death a sequence of tweens per lane with after(): fall off, come back with "elasticOut"
rise.event fake death opponent.scale with "elasticOut", a white flash, the colour back
scroller.event + .modchart breakdown the lanes across screen.width, wrapping round with %; an ease written by hand
switcheroo.event rebuild, final drop the fighters jump and swap places: .x / .z in the fight's frame, .turn 180
scroll_twist.event + .modchart rebuild text properties (strum[lane].scroll), player.downscroll
kick_hit.event final drop fx.chromatic + fx.bloom on every beat
logo_bump.event final drop the song's logo.png on the "lanes" layer: on the strum background, under the notes
upside_down.event + .modchart final drop hud.angle 180 with camera.roll -180 so the world stays upright, the lanes mirrored with strums.spacing
halo.modchart outro .x / .y / .scale / .alpha from one angle per lane: a ring with depth
finale.event + .modchart outro live player.score / player.accuracy on the "top" layer, onEnd
power_off.event the end the same shader played backwards, ending on screen.color

The files

All of them, in the order the song shows them (each file's first comment line has the same number).

power_on.event
format 1.1
-- Event Showcase 1/31: the song switches on like an old TV - a dot, a line, then the picture - with the
-- title flickering in on the curved screen. After two bars the TV look fades away.
-- Shows: a song's own shader (shaders/crt.fsh) driven by its four numbers, after() for a sequence.

event {
    name = "Power On",
    color = #5CF2FF,
    category = "Screen",
    description = "The screen opens from a dot like an old TV, with the title on it.",
}

params {
    title    = text { from = "value1", default = "EVENT SHOWCASE", label = "Title" },
    subtitle = text { from = "value2", label = "Subtitle" },
}

local glowing = false

function onEvent(p)
    -- crt.fsh: a = curvature, b = open sideways, c = open up and down, d = scanlines.
    shader[0].file = "crt.fsh"
    shader[0].amount = 1
    shader[0].a = 1
    shader[0].b = 0
    shader[0].c = 0
    shader[0].d = 1

    -- A dot grows into a line, the line opens into the picture.
    tween(shader[0].b, 1, beats(1), "expoOut")
    after(beats(1), function() tween(shader[0].c, 1, beats(2), "expoOut") end)

    text[0].value = upper(p.title)
    text[0].x = 0.5
    text[0].y = 0.34
    text[0].size = 3.2
    text[0].color = #5CF2FF
    text[0].layer = "top"
    text[0].alpha = 0

    text[1].value = p.subtitle ?? ""
    text[1].x = 0.5
    text[1].y = 0.46
    text[1].size = 1
    text[1].color = #FF6EC7
    text[1].layer = "top"
    text[1].alpha = 0

    -- The title warms up with the tube: it flickers for a beat, then holds.
    after(beats(2.5), function() glowing = true end)
    after(beats(3.5), function()
        glowing = false
        text[0].alpha = 1
        tween(text[1].alpha, 1, beats(1))
    end)

    -- Two and a half bars later the TV look fades out and the title goes.
    after(beats(10), function()
        tween(shader[0].a, 0, beats(2), "sineInOut")
        tween(shader[0].d, 0, beats(2), "sineInOut")
        tween(shader[0].amount, 0, beats(2), "sineInOut")
        tween(text[0].alpha, 0, beats(1))
        tween(text[0].size, 4, beats(1), "expoIn")
        tween(text[1].alpha, 0, beats(1))
    end)

    after(beats(12), function()
        shader[0].file = ""
        text[0].value = ""
        text[1].value = ""
    end)
end

function onFrame(dt)
    if glowing then
        text[0].alpha = chance(0.6) ? random(0.5, 1) : 0.1
    end
end
shaders/crt.fsh
// Overdrive's old TV: a curved screen with rounded corners and scanlines, which can open out of a
// line and close into a dot like a CRT switching on and off.
// params.x = curvature (0-1), .y = how far it's open sideways (0-1), .z = how far it's open up and
// down (0-1), .w = scanlines (0-1).
vec4 effect(vec2 uv) {
    vec2 c = uv * 2.0 - 1.0;
    c *= 1.0 + 0.1 * params.x * dot(c, c);

    // The picture squeezed into the open part: a thin line is the whole picture pressed flat.
    vec2 open = max(vec2(params.y, params.z), vec2(0.004));
    vec2 q = c / open;

    // A rounded rectangle: the corners round off with the curvature.
    float n = mix(40.0, 7.0, clamp(params.x, 0.0, 1.0));
    float e = pow(pow(abs(q.x), n) + pow(abs(q.y), n), 1.0 / n);

    if (e > 1.0) {
        return vec4(0.0, 0.0, 0.0, 1.0);
    }

    vec2 st = q * 0.5 + 0.5;
    vec3 col = pixel(st).rgb;

    // All the light pressed into the line: the tighter, the brighter.
    float squeeze = (1.0 - open.x) + (1.0 - open.y);
    col *= 1.0 + 3.0 * squeeze;

    col *= 1.0 - params.w * 0.2 * (0.5 + 0.5 * sin(st.y * resolution.y * 3.14159));
    // A brighter band rolling slowly down the tube.
    col *= 1.0 + 0.05 * params.w * sin((st.y + time * 0.3) * 6.2831);
    // Darker toward the curved edges.
    col *= mix(1.0, smoothstep(1.0, 0.8, e), params.x);

    return vec4(col, 1.0);
}
caption.event
format 1.1
-- Event Showcase 2/31: names what's on screen. Each caption slides in from the left with its number and
-- slides out again; a newer one takes the place of an older one.
-- Shows: a counter kept for the whole song, a closure that checks whether it's still the newest.

event {
    name = "Caption",
    color = #B9A6FF,
    category = "Text",
    description = "A numbered caption top left: the event and what it uses.",
}

params {
    title = text { from = "value1", label = "Event" },
    line  = text { from = "value2", label = "What it uses" },
}

local count = 0

local function slideIn(slot, delay)
    text[slot].x = -0.5
    text[slot].alpha = 1
    after(delay, function() tween(text[slot].x, 0.03, beats(0.6), "backOut") end)
end

function onEvent(p)
    count += 1
    local mine = count

    text[5].value = (count < 10 ? "0" : "") .. count .. "  " .. upper(p.title ?? "?")
    text[5].align = "left"
    text[5].y = 0.11
    text[5].size = 1.1
    text[5].color = #5CF2FF
    text[5].layer = "top"
    slideIn(5, 0)

    text[6].value = p.line ?? ""
    text[6].align = "left"
    text[6].y = 0.11 + 0.065
    text[6].size = 0.7
    text[6].color = #F2ECFF
    text[6].layer = "top"
    slideIn(6, beats(0.15))

    after(beats(7), function()
        if count == mine then
            tween(text[5].x, -0.6, beats(0.6), "backIn")
            tween(text[6].x, -0.6, beats(0.6), "backIn")
        end
    end)
end
cam_sway.event
format 1.1
-- Event Showcase 3/31: a handheld-camera drift.
-- Shows: onFrame(dt), noise() (smooth and repeatable), easing a script variable by hand, and reading
-- the shared "hype" value other events write - the louder the song gets, the more it sways.

event {
    name = "Cam Sway",
    color = #7CC8FF,
    category = "Screen",
    description = "The playfield drifts like a handheld camera. Off eases it back to rest.",
}

params {
    enabled = switch { from = "value1", label = "On" },
    amount  = number { from = "value2", default = 6, min = 0, max = 40, step = 1, label = "Drift (px)" },
}

shared hype = 0

local target = 0
local amp = 0
local moving = false

function onEvent(p)
    target = p.enabled ? p.amount : 0
end

function onFrame(dt)
    local goal = target * (0.6 + hype)

    -- Ease toward the goal at the same speed whatever the frame rate is.
    amp += (goal - amp) * min(1, dt / 500)

    if amp < 0.05 and goal == 0 then
        if moving then
            moving = false
            hud.x = 0
            hud.y = 0
        end
        return
    end

    moving = true
    hud.x = noise(time / 1100) * amp
    hud.y = noise(time / 1400 + 37) * amp * 0.6
end
judge_glow.event
format 1.1
-- Event Showcase 4/31: every hit pops its lane, every miss shakes it.
-- Shows: onHit(note) and onMiss(note) with note.lane / note.judgment / note.offset, a function of your
-- own that returns a value, and the shared "hype" making the pops bigger in the drops.

event {
    name = "Judge Glow",
    color = #FFD166,
    category = "Lanes",
    description = "Hit notes pop their lane (bigger for better judgments), misses flash red and shake the lane.",
}

params {
    enabled = switch { from = "value1", label = "On" },
}

shared hype = 0

local active = false

-- How far a judgment pops its lane.
local function popFor(judgment)
    if judgment == "sick" then return 0.3 end
    if judgment == "good" then return 0.18 end
    return 0.08
end

function onEvent(p)
    active = p.enabled
end

function onHit(note)
    if not active then return end

    local lane = note.lane
    strum[lane].scale = 1 + popFor(note.judgment) * (0.7 + 0.5 * hype)
    tween(strum[lane].scale, 1, steps(3), "backOut")

    -- A dead-on hit (within 15 ms) also nudges the camera.
    if abs(note.offset) < 15 then
        camera.bump += 0.006
    end
end

function onMiss(note)
    if not active then return end

    flash.color = #FF2050
    flash.alpha = 0.22
    tween(flash.alpha, 0, beats(0.5), "quadOut")

    strum[note.lane].wobbleX = 12
    tween(strum[note.lane].wobbleX, 0, beats(0.6), "elasticOut")
end
cam_follow.event
format 1.1
-- Event Showcase 5/31: the fight camera follows whoever sings. The opponent sings: it leans in toward
-- them. You sing: it pulls back and turns toward you. A bar without notes: back to the middle.
-- Shows: onHit and onOpponentHit as input, one value eased every frame that drives three properties.

event {
    name = "Cam Follow",
    color = #FFB35C,
    category = "Camera",
    description = "The fight camera leans toward whoever sings (0 = off).",
}

params {
    amount = number { from = "value1", default = 1, min = 0, max = 2, step = 0.1, label = "Strength" },
}

local amount = 0
-- -1 = you sing, 1 = the opponent, 0 = nobody.
local target = 0
local level = 0
local lastNote = -100000

function onEvent(p)
    amount = p.amount

    -- Off: let go at once and glide home, so another camera event can take over right away.
    if amount == 0 and level != 0 then
        level = 0
        tween(camera.x, 0, beats(1), "sineInOut")
        tween(camera.z, 0, beats(1), "sineInOut")
        tween(camera.yaw, 0, beats(1), "sineInOut")
    end
end

function onHit(note)
    target = -1
    lastNote = time
end

function onOpponentHit(note)
    target = 1
    lastNote = time
end

function onFrame(dt)
    if amount == 0 then return end

    if time - lastNote > beats(4) then target = 0 end

    level += (target * amount - level) * min(1, dt / 450)

    -- Toward the opponent: in and a little to the left. Toward you: back and to the right.
    camera.z = level * 0.6
    camera.x = level * -0.25
    camera.yaw = level * -1.5
end
opponent_echo.event
format 1.1
-- Event Showcase 6/31: the strumline leans toward every note the opponent sings.
-- Shows: onOpponentHit(note), turning a lane into a direction with a function that returns early, and a
-- coloured vignette pulse.

event {
    name = "Opponent Echo",
    color = #A78BFA,
    category = "Lanes",
    description = "Each opponent note pushes your strumline a little in its arrow's direction.",
}

params {
    enabled = switch { from = "value1", label = "On" },
    push    = number { from = "value2", default = 8, min = 0, max = 40, step = 1, label = "Push (px)" },
}

local active = false
local push = 8

-- Left, down, up, right as x / y steps.
local function stepX(lane)
    if lane == 0 then return -1 end
    if lane == 3 then return 1 end
    return 0
end

local function stepY(lane)
    if lane == 1 then return 1 end
    if lane == 2 then return -1 end
    return 0
end

function onEvent(p)
    active = p.enabled
    push = p.push

    if not active then
        tween(strums.x, 0, beats(0.5))
        tween(strums.y, 0, beats(0.5))
    end
end

function onOpponentHit(note)
    if not active then return end

    strums.x = stepX(note.lane) * push
    strums.y = stepY(note.lane) * push
    tween(strums.x, 0, beats(0.75), "quadOut")
    tween(strums.y, 0, beats(0.75), "quadOut")

    vignette.color = #7C3AED
    vignette.alpha = note.hold ? 0.5 : 0.3
    tween(vignette.alpha, 0, beats(0.75))
end
combo_meter.event
format 1.1
-- Event Showcase 7/31: a song script. The chart never calls this event - it runs from the first note to
-- the last just because the file is in the song folder, like a Psych song script.
-- Shows: onHit / onMiss without any chart event, player.combo, keeping state between callbacks, and a
-- colour that climbs the wheel with the combo.

event {
    name = "Combo Meter",
    color = #4ADE80,
    category = "Text",
    description = "No chart event needed: shouts every 25 combo, and tells you when a long combo breaks.",
}

local every = 25
local nextShout = 25
local lastCombo = 0

local function shout(message, tint)
    text[4].value = message
    text[4].x = 0.84
    text[4].y = 0.58
    text[4].color = tint
    text[4].alpha = 1
    text[4].angle = -8
    text[4].size = 1.8
    tween(text[4].size, 1.2, beats(0.5), "backOut")
    tween(text[4].angle, 0, beats(0.5), "backOut")
    tween(text[4].alpha, 0, beats(1.5), "quadIn")
end

function onHit(note)
    lastCombo = player.combo

    if player.combo >= nextShout then
        shout(nextShout .. " COMBO!", hsv(nextShout * 3 % 360, 0.7, 1))
        nextShout += every
    end
end

function onMiss(note)
    if lastCombo >= every then
        shout("COMBO BROKEN (" .. lastCombo .. ")", #FF4060)
    end

    lastCombo = 0
    nextShout = every
end
spotlight.event
format 1.1
-- Event Showcase 8/31: a spotlight that follows the melody.
-- Shows: onHit and onOpponentHit sharing one function, per-lane tweens in a loop, a darker strum
-- background (underlay.alpha), and the shared "hype" turned down for the quiet part.

event {
    name = "Spotlight",
    color = #FFF27A,
    category = "Lanes",
    description = "Darkens the screen; only the lane of the note just sung (by you or the opponent) stays lit.",
}

params {
    enabled = switch { from = "value1", label = "On" },
    dim     = number { from = "value2", default = 0.25, min = 0, max = 1, step = 0.05, label = "Unlit lanes" },
}

shared hype = 0

local active = false
local dim = 0.25

local function light(lit)
    for lane = 0, 3 do
        tween(strum[lane].alpha, lane == lit ? 1 : dim, steps(2), "sineOut")
    end
end

function onEvent(p)
    active = p.enabled
    dim = p.dim

    if active then
        hype = 0.15
        vignette.color = #000000
        tween(vignette.alpha, 0.8, beats(1))
        tween(underlay.alpha, 0.9, beats(1))
        light(-1)
    else
        tween(vignette.alpha, 0, beats(1))
        tween(underlay.alpha, 0.65, beats(1))
        for lane = 0, 3 do
            tween(strum[lane].alpha, 1, beats(1))
        end
    end
end

function onHit(note)
    if active then light(note.lane) end
end

function onOpponentHit(note)
    if active then light(note.lane) end
end
jiggle.event
format 1.1
-- Event Showcase 9/31: the receptors get kicked around on the rhythm and settle again - the modchart
-- "kick": a sideways jolt on 0, 0.75, 1.5 and 2.25 of every bar, an up-and-down jolt on 3 and 3.5, each
-- the other way round than the last.
-- Shows: onStep(n) as a rhythm grid, the wobble channels (they stack on .x / .y), local functions.

event {
    name = "Jiggle",
    color = #5CF2FF,
    category = "Lanes",
    description = "The receptors jolt on a rhythm and settle (pixels, 0 = off).",
}

params {
    amount = number { from = "value1", default = 24, min = 0, max = 60, step = 1, label = "Pixels" },
    rhythm = choice { from = "value2", options = { "kick", "beat", "eighths" }, label = "Rhythm" },
}

local amount = 0
local rhythm = "kick"
local flipX = 1
local flipY = 1

-- The whole row sideways.
local function side()
    flipX = -flipX
    for lane = 0, 3 do
        strum[lane].wobbleX = amount * flipX
        tween(strum[lane].wobbleX, 0, beats(0.75), "cubicOut")
    end
end

-- Up and down, every lane a bit differently (the cosine of the lane), so the row zigzags.
local function updown()
    flipY = -flipY
    for lane = 0, 3 do
        strum[lane].wobbleY = amount * 0.8 * flipY * cos(lane * 2)
        tween(strum[lane].wobbleY, 0, beats(0.75), "cubicOut")
    end
end

function onEvent(p)
    amount = p.amount
    rhythm = p.rhythm
end

function onStep(n)
    if amount == 0 then return end

    local s = n % 16

    if rhythm == "kick" then
        if s == 0 or s == 3 or s == 6 or s == 9 then side() end
        if s == 12 or s == 14 then updown() end
    elseif rhythm == "beat" then
        if s % 4 == 0 then side() end
    elseif s % 2 == 0 then
        if s % 4 == 0 then side() else updown() end
    end
end
build_up.event
format 1.1
-- Event Showcase 10/31: the build-up before the drop.
-- Shows: onStep(step) with patterns that speed up (every 4th step, then every 2nd, then every one), a
-- for loop that schedules a 3-2-1 with after(), writing the shared "hype" value, and a beat of silence
-- at the end.

event {
    name = "Build Up",
    color = #FF8A3D,
    category = "Screen",
    description = "Zoom, dark edges, shake and flashes build up over the given beats; 3-2-1 at the end.",
}

params {
    length = number { from = "value1", default = 16, min = 4, max = 64, step = 1, label = "Length (beats)" },
}

shared hype = 0

local active = false
local startBeat = 0
local total = 16

function onEvent(p)
    active = true
    startBeat = beat
    total = p.length

    tween(camera.zoom, 1.12, beats(total - 1), "quadIn")
    vignette.color = #000000
    tween(vignette.alpha, 0.7, beats(total - 1), "quadIn")

    -- 3, 2, 1 on the last three beats.
    for i = 1, 3 do
        after(beats(total - 4 + i), function()
            text[3].value = str(4 - i)
            text[3].x = 0.5
            text[3].y = 0.42
            text[3].color = i == 3 ? #FF5050 : #FFFFFF
            text[3].alpha = 1
            text[3].size = 5
            tween(text[3].size, 3, beats(1), "expoOut")
            tween(text[3].alpha, 0, beats(1), "quadIn")
        end)
    end

    -- The end: everything drops away at once (the drop takes it from there).
    after(beats(total), function()
        active = false
        text[3].value = ""
        camera.shake = 0
        tween(camera.zoom, 1, steps(2))
        tween(vignette.alpha, 0, beats(1))
    end)
end

function onStep(s)
    if not active then return end

    local progress = clamp((beat - startBeat) / total, 0, 1)
    hype = progress

    -- The last beat is silence before the drop - nothing moves.
    if beat - startBeat >= total - 1 then
        camera.shake = 0
        return
    end

    camera.shake = 0.004 * progress ^ 2
    local every = progress < 0.5 ? 4 : progress < 0.75 ? 2 : 1

    if s % every == 0 then
        camera.bump += 0.008 + 0.02 * progress
        flash.color = #FFFFFF
        flash.alpha = 0.1 * progress
        tween(flash.alpha, 0, steps(1))
    end
end
kade_sway.event
format 1.1
-- Event Showcase 11/31: the lanes sway in a wave, each a quarter beat behind the one before - the
-- modchart's "kade sway". Gentle: they bob up and down a little. Wild: the up-and-down is a tangent, so
-- once a bar they shoot off the screen (half up, half down) and come back from the other side.
-- Shows: the song position in beats with fractions (time / beats(1)), tan(), a level faded in and out.

event {
    name = "Kade Sway",
    color = #8F7CFF,
    category = "Lanes",
    description = "The lanes sway in a wave. Wild = they fly off the screen once a bar (keep it to bars without your notes).",
}

params {
    mode   = choice { from = "value1", options = { "off", "gentle", "wild" }, label = "Mode" },
    amount = number { from = "value2", default = 20, min = 0, max = 60, step = 1, label = "Pixels" },
}

local mode = "off"
local amount = 20
local target = 0
local level = 0

function onEvent(p)
    if p.mode != "off" then
        mode = p.mode
        amount = p.amount
    end

    target = p.mode == "off" ? 0 : 1
end

function onFrame(dt)
    if target == 0 and level < 0.001 then return end

    level += (target - level) * min(1, dt / 300)
    local b = time / beats(1)
    -- Far enough to be off the screen, not further.
    local far = screen.height * 1.2

    for lane = 0, 3 do
        local mu = lane % 2 == 0 ? 1 : -1
        strum[lane].x = level * amount * sin((b + lane * 0.25) * pi)

        if mode == "wild" then
            strum[lane].y = level * clamp(amount * 1.5 * mu * tan(b * 0.25 * pi), -far, far)
        else
            strum[lane].y = level * amount * 0.5 * mu * sin(b * 0.25 * pi)
        end
    end

    if target == 0 and level < 0.001 then
        for lane = 0, 3 do
            strum[lane].x = 0
            strum[lane].y = 0
        end
    end
end
spin.event
format 1.1
-- Event Showcase 12/31: the receptors spin round and slow down into place - the modchart's "confusion"
-- spin. Once, or on every bar / every other bar, each time the other way.
-- Shows: onBeat(b) counted in bars from where the event sits, a guard so a beat never spins twice.

event {
    name = "Spin",
    color = #C45CFF,
    category = "Lanes",
    description = "The receptors spin round and settle: once, or on every (other) bar until Stop.",
}

params {
    mode  = choice { from = "value1", options = { "once", "every bar", "every 2 bars", "stop" }, label = "When" },
    turns = number { from = "value2", default = 1, min = 1, max = 3, step = 1, label = "Turns" },
}

local every = 0
local turns = 1
local dir = 1
local fromBar = 0
local lastBeat = -1

local function spinAt(b)
    if b == lastBeat then return end

    lastBeat = b
    dir = -dir

    for lane = 0, 3 do
        strum[lane].angle = 360 * turns * dir
        tween(strum[lane].angle, 0, beats(2), "cubicOut")
    end
end

function onEvent(p)
    turns = p.turns
    every = p.mode == "every bar" ? 1 : p.mode == "every 2 bars" ? 2 : 0
    fromBar = round(time / beats(4))

    if p.mode != "stop" then spinAt(round(time / beats(1))) end
end

function onBeat(b)
    if every == 0 or b % 4 != 0 then return end

    if (b / 4 - fromBar) % every == 0 then spinAt(b) end
end
the_drop.event
format 1.1
-- Event Showcase 13/31: the drop.
-- Shows: an impact (flash, zoom punch, shake that dies down), onBeat(beat) with a kick / snare pattern,
-- a colour per bar from hsv(), and setting the shared "hype" for everyone else.

event {
    name = "The Drop",
    color = #FF3D6E,
    category = "Screen",
    description = "On: a big impact, then the playfield punches on every kick and tilts on every snare. Off: calms down.",
}

params {
    enabled = switch { from = "value1", label = "On" },
}

shared hype = 0

local active = false
local bars = 0

function onEvent(p)
    active = p.enabled

    if not active then
        hype = 0.3
        tween(hud.angle, 0, beats(1))
        return
    end

    hype = 1
    bars = 0

    flash.color = #FFFFFF
    flash.alpha = 1
    tween(flash.alpha, 0, beats(2), "quadOut")
    camera.bump += 0.14
    camera.shake = 0.012
    tween(camera.shake, 0, beats(2), "quadOut")
end

function onBeat(b)
    if not active then return end

    -- Kick on every beat: a zoom punch.
    camera.bump += 0.022 * hype

    -- Snare on 2 and 4: the playfield tilts, left on one bar, right on the next.
    if b % 2 == 1 then
        local side = floor(b / 4) % 2 == 0 ? 1 : -1
        hud.angle = side * 1.8
        tween(hud.angle, 0, beats(0.9), "backOut")
    end

    -- New bar: a soft flash in the next colour round the wheel.
    if b % 4 == 0 then
        bars += 1
        flash.color = hsv(bars * 67, 0.75, 1)
        flash.alpha = 0.16
        tween(flash.alpha, 0, beats(1))
    end
end
shockwave.event
format 1.1
-- Event Showcase 14/31: an impact. A ring runs out over the screen (shaders/shockwave.fsh) and knocks
-- both fighters back: tipped over their heels, squashed, pushed apart - then they spring back.
-- Shows: handing a shader its start time, a shader slot switched off again once it's done, the
-- fighters' pitch / squash / z with "elasticOut".

event {
    name = "Shockwave",
    color = #5CF2FF,
    category = "Screen",
    description = "A ring runs out over the screen and knocks both fighters back.",
}

params {
    strength = number { from = "value1", default = 1, min = 0.2, max = 2, step = 0.1, label = "Strength" },
}

local count = 0

function onEvent(p)
    local s = p.strength
    count += 1
    local mine = count

    -- shockwave.fsh: a = strength, b = speed, c = when it started (song seconds).
    shader[1].file = "shockwave.fsh"
    shader[1].amount = 1
    shader[1].a = s
    shader[1].b = 1.3
    shader[1].c = time / 1000
    after(seconds(1.5), function()
        if count == mine then shader[1].file = "" end
    end)

    camera.shake = 0.012 * s
    tween(camera.shake, 0, beats(1), "quadOut")

    -- Both get pushed apart from wherever they stand right now (Switcheroo may have swapped them).
    local pz = player.z
    local oz = opponent.z
    local apart = player.z <= opponent.z ? 1 : -1
    player.pitch = -14 * s
    player.squash = 0.3 * s
    player.z = pz - 0.35 * s * apart
    opponent.pitch = -14 * s
    opponent.squash = 0.3 * s
    opponent.z = oz + 0.35 * s * apart

    tween(player.pitch, 0, beats(1.5), "elasticOut")
    tween(player.squash, 0, beats(1.2), "elasticOut")
    tween(player.z, pz, beats(1), "cubicOut")
    tween(opponent.pitch, 0, beats(1.5), "elasticOut")
    tween(opponent.squash, 0, beats(1.2), "elasticOut")
    tween(opponent.z, oz, beats(1), "cubicOut")
end
shaders/shockwave.fsh
// A ring that runs out from the middle, bending the picture as it passes, with a cyan rim.
// params.x = strength, .y = speed (screen heights per second), .z = the moment it started (song
// seconds - a shader keeps no memory, so the script hands it the start).
vec4 effect(vec2 uv) {
    float age = time - params.z;

    if (age < 0.0 || age > 1.4) {
        return pixel(uv);
    }

    vec2 aspect = vec2(resolution.x / resolution.y, 1.0);
    vec2 d = (uv - 0.5) * aspect;
    float r = length(d);
    float ring = r - age * params.y;
    float fade = 1.0 - age / 1.4;
    float bend = exp(-(ring * ring) / 0.004) * params.x * fade;
    vec2 dir = d / max(r, 0.0001);

    // The three colours bent a little differently: a rainbow rim on the ring.
    vec2 off = dir / aspect * bend * 0.04;
    vec3 c = vec3(pixel(uv - off * 1.25).r, pixel(uv - off).g, pixel(uv - off * 0.75).b);
    c += bend * 0.22 * vec3(0.36, 0.95, 1.0);
    return vec4(c, 1.0);
}
lane_lights.event
format 1.1
-- Event Showcase 15/31: the strum background as a light panel.
-- Shows: the strum background (underlay.color, underlay.alpha, underlay.width), colour tweens that
-- blend channel by channel, and a beat pattern that alternates two colours with the bar.

event {
    name = "Lane Lights",
    color = #FF7AE0,
    category = "Lanes",
    description = "The strum background lights up on every beat in the song's colours. Off = back to the plain dark stripe.",
}

params {
    enabled = switch { from = "value1", label = "On" },
    first   = color  { from = "value2.1", default = #6A1B9A, label = "Colour A" },
    second  = color  { from = "value2.2", default = #00838F, label = "Colour B" },
}

local active = false
local first = #6A1B9A
local second = #00838F

-- Colour A for one bar, colour B for the next; every beat flares up and dims again.
local function flare(b)
    local lit = floor(b / 4) % 2 == 0 ? first : second
    underlay.color = mix(lit, #FFFFFF, 0.25)
    underlay.alpha = 0.95
    tween(underlay.color, lit, beats(0.8), "quadOut")
    tween(underlay.alpha, 0.7, beats(0.8), "quadOut")
end

function onEvent(p)
    active = p.enabled
    first = p.first
    second = p.second

    if active then
        -- The first flare at once; onBeat takes over from the next beat.
        flare(beat)
        tween(underlay.width, 1.15, beats(0.5), "backOut")
        return
    end

    tween(underlay.color, #000000, beats(1))
    tween(underlay.alpha, 0.65, beats(1))
    tween(underlay.width, 1, beats(1))
end

function onBeat(b)
    if active then flare(b) end
end
hop.event
format 1.1
-- Event Showcase 16/31: the lanes hop in turns - two jump on one beat and land on the next kick, the
-- other two jump on the next. Always toward the middle of the screen, so they never hop off it.
-- Shows: max(0, sin()) as a bouncing ball, strum[lane].isDown to know which way is "in".

event {
    name = "Hop",
    color = #9BFF5C,
    category = "Lanes",
    description = "The lanes hop in turns on the beat (pixels, 0 = off).",
}

params {
    amount = number { from = "value1", default = 22, min = 0, max = 60, step = 1, label = "Pixels" },
}

local amount = 22
local target = 0
local level = 0

function onEvent(p)
    if p.amount > 0 then amount = p.amount end
    target = p.amount > 0 ? 1 : 0
end

function onFrame(dt)
    if target == 0 and level < 0.001 then return end

    level += (target - level) * min(1, dt / 200)
    local b = time / beats(1)

    for lane = 0, 3 do
        -- Half a sine: up and down again within one beat. Even lanes on even beats, odd on odd.
        local arc = max(0, sin((b + lane) * pi))
        local toMiddle = strum[lane].isDown ? -1 : 1
        strum[lane].y = toMiddle * level * amount * arc
    end

    if target == 0 and level < 0.001 then
        for lane = 0, 3 do strum[lane].y = 0 end
    end
end
dance_routine.event
format 1.1
-- Event Showcase 17/31: both fighters drop MineFunkin's own animation and dance a routine of eight
-- moves, one per beat - the opponent mirrored, so they dance like a reflection.
-- Shows: player.animate = false, body parts (pitch / yaw / roll), your own functions as moves, a mirror
-- flag that swaps left and right, puppet[i] with a variable index.

event {
    name = "Dance Routine",
    color = #FFD15C,
    category = "Fighters",
    description = "Both fighters stop their own animation and dance eight moves, one per beat.",
}

params {
    on = bool { from = "value1", default = true, label = "On" },
}

local active = false
local moveTime = 0

-- One arm: side 0 = left, 1 = right. pitch + = forward, roll + = outward (see the docs).
local function arm(who, side, pitch, roll)
    if side == 0 then
        tween(puppet[who].leftArm.pitch, pitch, moveTime, "backOut")
        tween(puppet[who].leftArm.roll, roll, moveTime, "backOut")
    else
        tween(puppet[who].rightArm.pitch, pitch, moveTime, "backOut")
        tween(puppet[who].rightArm.roll, roll, moveTime, "backOut")
    end
end

local function leg(who, side, pitch, roll)
    if side == 0 then
        tween(puppet[who].leftLeg.pitch, pitch, moveTime, "backOut")
        tween(puppet[who].leftLeg.roll, roll, moveTime, "backOut")
    else
        tween(puppet[who].rightLeg.pitch, pitch, moveTime, "backOut")
        tween(puppet[who].rightLeg.roll, roll, moveTime, "backOut")
    end
end

local function lean(who, roll, nod)
    tween(puppet[who].body.roll, roll, moveTime, "backOut")
    tween(puppet[who].head.roll, -roll * 0.6, moveTime, "backOut")
    tween(puppet[who].head.pitch, nod, moveTime, "backOut")
end

-- The moves. `m` mirrors: the opponent uses its other arm and leans the other way.
local function clap(who, m)
    arm(who, 0, 75, -18)
    arm(who, 1, 75, -18)
    leg(who, 0, 0, 4)
    leg(who, 1, 0, 4)
    lean(who, 0, 10)
end

local function spread(who, m)
    arm(who, 0, 0, 90)
    arm(who, 1, 0, 90)
    lean(who, 0, -12)
end

local function reach(who, m)
    local up = m ? 0 : 1
    arm(who, up, 10, 165)
    arm(who, 1 - up, 0, 15)
    lean(who, m ? 10 : -10, -8)
end

local function point(who, m)
    local hand = m ? 0 : 1
    arm(who, hand, 95, 5)
    arm(who, 1 - hand, -25, 30)
    lean(who, m ? -6 : 6, 0)
end

local function squat(who, m)
    arm(who, 0, 50, 25)
    arm(who, 1, 50, 25)
    leg(who, 0, 0, 16)
    leg(who, 1, 0, 16)
    puppet[who].squash = 0.25
    tween(puppet[who].squash, 0, beats(1), "elasticOut")
    lean(who, 0, 15)
end

local function jump(who, m)
    arm(who, 0, 0, 165)
    arm(who, 1, 0, 165)
    leg(who, 0, 0, 0)
    leg(who, 1, 0, 0)
    lean(who, 0, -15)
    tween(puppet[who].y, 0.5, beats(0.25), "quadOut")
    after(beats(0.25), function() tween(puppet[who].y, 0, beats(0.25), "quadIn") end)
end

local function spin(who, m)
    arm(who, 0, 0, 70)
    arm(who, 1, 0, 70)
    lean(who, 0, 0)
    puppet[who].turn = 0
    tween(puppet[who].turn, m ? -360 : 360, beats(0.9), "quadInOut")
end

local function kick(who, m)
    local foot = m ? 0 : 1
    leg(who, foot, 70, 0)
    leg(who, 1 - foot, -10, 0)
    arm(who, foot, -30, 25)
    arm(who, 1 - foot, 40, 25)
    lean(who, 0, 0)
end

local function move(who, n)
    local m = who == 1
    local k = n % 8
    if k == 0 then clap(who, m)
    elseif k == 1 then spread(who, m)
    elseif k == 2 then reach(who, m)
    elseif k == 3 then point(who, m)
    elseif k == 4 then squat(who, m)
    elseif k == 5 then kick(who, m)
    elseif k == 6 then jump(who, m)
    else spin(who, m) end
end

function onEvent(p)
    active = p.on
    moveTime = beats(0.25)

    if p.on then
        player.animate = false
        opponent.animate = false
    else
        resetPuppet("both", beats(1))
    end
end

function onBeat(b)
    if not active then return end

    move(0, b)
    move(1, b)
end
orbit_cam.event
format 1.1
-- Event Showcase 18/31: the camera swings around the fighters (fights only).
-- Shows: camera.x / .y / .z / .yaw / .pitch together - moving and turning so the point between the
-- fighters stays in the middle, pulling back and rising the further it swings so both stay in view.

event {
    name = "Orbit Cam",
    color = #7C6BFF,
    category = "Camera",
    description = "Swings the fight camera around the fighters to an angle (0 = home).",
}

params {
    angle  = number { from = "value1", default = 30, min = -60, max = 60, step = 1, label = "Angle" },
    length = number { from = "value2", default = 8, min = 0, max = 32, step = 0.5, label = "Beats" },
}

-- The point it circles, from the camera, in blocks (right, ahead): halfway between the fighters in the
-- default fight layout. Positive angles swing it to the left side, away from the line through both
-- fighters - around -25 the opponent would hide right behind you.
local pivotX = 0.55
local pivotZ = 7.25
local from = 0
local to = 0
local duration = 0
local elapsed = 0
local moving = false

function onEvent(p)
    from = camera.yaw
    to = p.angle
    duration = max(1, beats(p.length))
    elapsed = 0
    moving = true
end

function onFrame(dt)
    if not moving then return end

    elapsed += dt
    local t = clamp(elapsed / duration, 0, 1)
    -- sineInOut by hand: the angle eases, and x / z follow it on the circle.
    local k = 0.5 - 0.5 * cos(t * 3.14159265)
    local angle = lerp(from, to, k)
    local a = angle * 3.14159265 / 180
    -- Further round = further back (up to 1.6 times the distance at 30 degrees) and higher.
    local back = 1 + 0.02 * abs(angle)
    local rx = -pivotX * cos(a) - pivotZ * sin(a)
    local rz = pivotX * sin(a) - pivotZ * cos(a)

    camera.yaw = angle
    camera.x = pivotX + rx * back
    camera.z = pivotZ + rz * back
    camera.y = 0.04 * abs(angle)
    camera.pitch = -0.15 * abs(angle)

    if t >= 1 then moving = false end
end
word_by_word.event
format 1.1
-- Event Showcase 19/31: lyrics that appear word by word.
-- Shows: up to six parameters read from the parts of one value ("EVERY,EFFECT,YOU,SEE"), a for loop
-- that builds the line and schedules each step with after() - every after() keeps the line as it was
-- when it was scheduled - and "break" once the words run out.

event {
    name = "Word by Word",
    color = #FFE066,
    category = "Text",
    description = "value1 = up to six words, comma separated; value2 = beats per word, colour.",
}

params {
    w1 = text { from = "value1.1", label = "Word 1" },
    w2 = text { from = "value1.2", label = "Word 2" },
    w3 = text { from = "value1.3", label = "Word 3" },
    w4 = text { from = "value1.4", label = "Word 4" },
    w5 = text { from = "value1.5", label = "Word 5" },
    w6 = text { from = "value1.6", label = "Word 6" },
    per  = number { from = "value2.1", default = 1, min = 0.25, max = 4, step = 0.25, label = "Beats per word" },
    tint = color  { from = "value2.2", default = #FFFFFF, label = "Colour" },
}

local shown = 0

function onEvent(p)
    shown += 1
    local mine = shown
    local line = ""
    local words = 0

    text[2].x = 0.5
    text[2].y = 0.72
    text[2].color = p.tint
    text[2].alpha = 1

    for i = 1, 6 do
        local word = i == 1 ? p.w1 : i == 2 ? p.w2 : i == 3 ? p.w3 : i == 4 ? p.w4 : i == 5 ? p.w5 : p.w6
        if word == nil then break end

        line = words == 0 ? word : line .. " " .. word
        words += 1

        local upTo = line
        after(beats((i - 1) * p.per), function()
            if shown != mine then return end
            text[2].value = upTo
            text[2].size = 1.6
            tween(text[2].size, 1.25, beats(0.5), "backOut")
        end)
    end

    -- The line stays two beats after its last word, then fades.
    after(beats(words * p.per + 2), function()
        if shown == mine then
            tween(text[2].alpha, 0, beats(1))
        end
    end)
end
fake_death.event
format 1.1
-- Event Showcase 20/31: the opponent drops dead in the middle of the song - for now.
-- Shows: opponent.pose = "death" (MineFunkin's own death), the colour draining, the camera looking
-- down.

event {
    name = "Fake Death",
    color = #6E6E8F,
    category = "Fighters",
    description = "The opponent dies (until Rise), the world loses its colour.",
}

function onEvent(p)
    opponent.pose = "death"
    tween(fx.saturation, 0.15, beats(2))
    tween(fx.contrast, 1.25, beats(2))
    -- The camera turns to the body on the ground.
    tween(camera.yaw, -9, beats(4), "sineInOut")
    tween(camera.fov, -4, beats(4), "sineInOut")
    tween(camera.pitch, -4, beats(4), "sineInOut")
    tween(vignette.alpha, 0.6, beats(2))
    vignette.color = #000000
end
drop_out.event
format 1.1
-- Event Showcase 21/31: the lanes leave and come back like in the modchart. Out: one after the other
-- they hop up and fall off the bottom of the screen. In: they shoot up from below past their spot, drop
-- back a little and wobble into place - three beats, so place it three beats before your next note.
-- Shows: a sequence of tweens per lane with after(), the loop variable kept in each closure, the strum
-- background fading with them.

event {
    name = "Drop Out",
    color = #FF5C7A,
    category = "Lanes",
    description = "Out: the lanes fall off the screen one by one. In: they fly back and wobble into place (3 beats).",
}

params {
    way = choice { from = "value1", options = { "out", "in" }, label = "Way" },
}

-- The strum background's opacity before it went.
local under = 0.65

function onEvent(p)
    local far = screen.height * 1.15

    if p.way == "out" then
        under = underlay.alpha
        tween(underlay.alpha, 0, beats(2))
    else
        tween(underlay.alpha, under, beats(2))
    end

    for lane = 0, 3 do
        local d = beats(lane * 0.125)

        if p.way == "out" then
            after(d, function() tween(strum[lane].y, -40, beats(0.5), "expoOut") end)
            after(d + beats(0.5), function() tween(strum[lane].y, far, beats(1.25), "expoIn") end)
            after(d + beats(1.75), function() strum[lane].alpha = 0 end)
        else
            after(d, function()
                strum[lane].y = far
                strum[lane].alpha = 1
                tween(strum[lane].y, -40, beats(1), "expoOut")
            end)
            after(d + beats(1), function() tween(strum[lane].y, 30, beats(1), "expoIn") end)
            after(d + beats(2), function() tween(strum[lane].y, 0, beats(1.25), "elasticOut") end)
        end
    end
end
rise.event
format 1.1
-- Event Showcase 22/31: ...and it gets back up. Huge. For two bars.
-- Shows: opponent.pose back to "none", opponent.scale with "elasticOut", a white flash, the colour
-- back.

event {
    name = "Rise",
    color = #FF2E63,
    category = "Fighters",
    description = "The opponent stands up again, grows, then shrinks back two bars later.",
}

params {
    size = number { from = "value1", default = 2, min = 1, max = 3, step = 0.1, label = "Size" },
}

function onEvent(p)
    opponent.pose = "none"
    opponent.scale = 1
    tween(opponent.scale, p.size, beats(1.5), "elasticOut")

    flash.color = #FFFFFF
    flash.alpha = 0.85
    tween(flash.alpha, 0, beats(1), "quadOut")
    tween(fx.saturation, 1, beats(1))
    tween(fx.contrast, 1, beats(1))
    tween(vignette.alpha, 0, beats(1))
    tween(camera.fov, 0, beats(1))
    tween(camera.yaw, 0, beats(1), "backOut")
    tween(camera.pitch, 7, beats(1), "backOut")
    camera.shake = 0.02
    tween(camera.shake, 0, beats(1.5))

    after(beats(8), function()
        tween(opponent.scale, 1, beats(1), "elasticOut")
        tween(camera.pitch, 0, beats(1))
    end)
end
scroller.event
format 1.1
-- Event Showcase 23/31: the lanes spread out over the whole width of the screen and slide along it,
-- wrapping round at the edge - the modchart's scroller. Each one bobs toward the middle of the screen
-- while it travels. Switched off, they stop and glide home.
-- Shows: a lane's real spot on the screen (screen.width, strums.spacing), % to wrap round, an ease
-- written by hand (inOut) for values that aren't properties, the strum background faded meanwhile.

event {
    name = "Scroller",
    color = #5CFFB0,
    category = "Lanes",
    description = "The lanes spread across the screen and slide sideways, wrapping round at the edges.",
}

params {
    on    = bool   { from = "value1", default = true, label = "On" },
    speed = number { from = "value2", default = 1, min = -2, max = 2, step = 0.25, label = "Screens per 2 bars" },
}

-- 0 = idle, 1 = scrolling, 2 = gliding home.
local state = 0
local speed = 1
local onAt = 0
local offAt = 0
-- How far it has scrolled, in screen widths.
local pos = 0
-- The strum background's opacity before it faded.
local under = 0.65

local function inOut(t)
    t = clamp(t, 0, 1)
    return t < 0.5 ? 4 * t * t * t : 1 - pow(-2 * t + 2, 3) / 2
end

function onEvent(p)
    speed = p.speed

    if p.on and state != 1 then
        state = 1
        onAt = time
        pos = 0
        under = underlay.alpha
        tween(underlay.alpha, 0, beats(4))
    elseif not p.on and state == 1 then
        state = 2
        offAt = time
        tween(underlay.alpha, under, beats(2))
    end
end

function onFrame(dt)
    if state == 0 then return end

    local w = screen.width
    local s = strums.spacing

    -- A screen width every two bars, like the modchart (frozen while gliding home, so no lane wraps
    -- round on its way back).
    if state == 1 then pos += dt / beats(8) * speed end

    -- Spread from their own spacing to a quarter of the screen each, over a bar.
    local spread = inOut((time - onAt) / beats(4))
    local leave = state == 2 ? inOut((time - offAt) / beats(2)) : 0
    local gap = lerp(s, w / 4, spread)
    local left = lerp(w / 2 - 1.5 * s, w / 8, spread)
    local b = time / beats(1)

    for lane = 0, 3 do
        local home = w / 2 + (lane - 1.5) * s
        local x = (left + lane * gap + pos * w) % w
        local toMiddle = strum[lane].isDown ? -1 : 1
        local bob = toMiddle * screen.height * 0.05 * (1 + sin(b * pi + lane * pi / 2))

        strum[lane].x = (x - home) * (1 - leave)
        strum[lane].y = bob * spread * (1 - leave)
        -- A little see-through right at the edges, where a lane jumps round.
        strum[lane].alpha = lerp(1, clamp(0.35 + min(x, w - x) / 40, 0.35, 1), spread * (1 - leave))
    end

    if state == 2 and leave >= 1 then
        state = 0

        for lane = 0, 3 do
            strum[lane].x = 0
            strum[lane].y = 0
            strum[lane].alpha = 1
        end
    end
end
switcheroo.event
format 1.1
-- Event Showcase 24/31: the fighters jump over each other and swap places - and back, as often as you
-- like.
-- Shows: player.x / .z and opponent.x / .z in the fight's frame, .turn by 180 so they still face each
-- other, a jump arc from two tweens, a variable that remembers which side they're on.

event {
    name = "Switcheroo",
    color = #5CFFB5,
    category = "Fighters",
    description = "The fighters jump and swap places. swap = to the other side, on / off = swapped / home.",
}

params {
    mode = choice { from = "value1", options = { "swap", "on", "off" }, label = "Mode" },
}

-- Where the opponent stands from you, in blocks: the default fight layout (7.4 ahead, 3 to the left).
local ahead = 7.4
local side = -3
local swapped = false

local function hop(who, x, z, turn)
    local dur = beats(1)
    tween(puppet[who].x, x, dur, "sineInOut")
    tween(puppet[who].z, z, dur, "sineInOut")
    tween(puppet[who].turn, turn, dur, "sineInOut")
    -- The arc: up for half the time, down for the other half; stretched in the air, squashed on landing.
    tween(puppet[who].y, 2.5, dur / 2, "quadOut")
    after(dur / 2, function() tween(puppet[who].y, 0, dur / 2, "quadIn") end)
    puppet[who].squash = -0.2
    after(dur, function()
        puppet[who].squash = 0.3
        tween(puppet[who].squash, 0, beats(1), "elasticOut")
    end)
end

function onEvent(p)
    local want = p.mode == "swap" ? not swapped : p.mode == "on"

    if want == swapped then return end

    swapped = want

    if swapped then
        hop(0, side, ahead, 180)
        hop(1, -side, -ahead, 180)
    else
        hop(0, 0, 0, 0)
        hop(1, 0, 0, 0)
    end
end
scroll_twist.event
format 1.1
-- Event Showcase 25/31: lanes turn around.
-- Shows: text properties (strum[lane].scroll = "up" / "down" / "auto"), reading the player's own
-- setting (player.downscroll) so it works for both, and a little wiggle on every switch.

event {
    name = "Scroll Twist",
    color = #FF9F1C,
    category = "Lanes",
    description = "zigzag = lanes 2 and 4 scroll the other way, flip = all of them, normal = back to the player's setting.",
}

params {
    mode = choice { from = "value1", options = { "zigzag", "flip", "normal" }, default = "zigzag", label = "Mode" },
}

function onEvent(p)
    -- The other way from what the player plays with.
    local other = player.downscroll ? "up" : "down"

    for lane = 0, 3 do
        local turns = p.mode == "flip" or (p.mode == "zigzag" and lane % 2 == 1)
        strum[lane].scroll = turns ? other : "auto"

        strum[lane].scale = 0.7
        tween(strum[lane].scale, 1, beats(0.5), "backOut")
    end

    flash.color = #FF9F1C
    flash.alpha = 0.2
    tween(flash.alpha, 0, beats(0.5))
end
kick_hit.event
format 1.1
-- Event Showcase 26/31: every kick hits the picture - the colours split apart and the bright parts
-- flare up, a little harder on the first beat of a bar.
-- Shows: two built-in effects (fx.chromatic, fx.bloom) set and tweened back on every beat.

event {
    name = "Kick Hit",
    color = #FF6EC7,
    category = "Screen",
    description = "Every beat hits the picture: the colours split and it glows (0 = off).",
}

params {
    strength = number { from = "value1", default = 1, min = 0, max = 2, step = 0.1, label = "Strength" },
}

local strength = 0

function onEvent(p)
    strength = p.strength

    if strength == 0 then
        tween(fx.chromatic, 0, beats(0.5))
        tween(fx.bloom, 0, beats(0.5))
    end
end

function onBeat(b)
    if strength == 0 then return end

    local down = b % 4 == 0
    fx.chromatic = (down ? 6 : 3.5) * strength
    tween(fx.chromatic, 0, beats(0.5), "quadOut")
    fx.bloom = (down ? 0.7 : 0.4) * strength
    tween(fx.bloom, 0, beats(0.6), "quadOut")
end
logo_bump.event
format 1.1
-- Event Showcase 27/31: a picture from the song folder, bumped on the beat.
-- Shows: image slots (file, size, position, angle), LAYERS - "lanes" puts it on the strum background
-- but under the notes - onBeat, and "backOut" pops.
-- The picture is logo.png next to the chart; any .png in the song folder (or its events/) works.

event {
    name = "Logo Bump",
    color = #C77DFF,
    category = "Text",
    description = "Shows a picture on the strum background, under the notes, that bumps and rocks on every beat. Hide = it shrinks away.",
}

params {
    mode = choice { from = "value1", options = { "show", "hide" }, default = "show", label = "Mode" },
    file = text   { from = "value2", default = "logo.png", label = "Picture (.png)" },
}

local showing = false
local size = 0.3

function onEvent(p)
    if p.mode == "hide" then
        showing = false
        tween(image[1].width, 0, beats(1), "backIn")
        return
    end

    showing = true
    image[1].file = p.file
    -- On the strum background, under the notes: "back" would hide it behind the dark stripe,
    -- "front" would cover the notes.
    image[1].layer = "lanes"
    image[1].x = 0.5
    image[1].y = 0.45
    image[1].alpha = 1
    image[1].width = 0
    tween(image[1].width, size, beats(1), "backOut")
end

function onBeat(b)
    if not showing then return end

    image[1].width = size * 1.12
    tween(image[1].width, size, beats(0.6), "quadOut")
    image[1].angle = b % 2 == 0 ? 5 : -5
    tween(image[1].angle, 0, beats(0.9), "backOut")
end
upside_down.event
format 1.1
-- Event Showcase 28/31: the whole playfield turns over in one bar - the modchart's "rotationz 180". The
-- notes come from the other side, but the lanes swap back into their order and the arrows turn back
-- upright on the way, so it plays like the other scroll direction. The world stays upright: in a fight
-- the camera rolls with hud.angle, and camera.roll turns it back.
-- Shows: hud.angle + camera.roll cancelling out, hud.extras, the lanes mirrored with strums.spacing.

event {
    name = "Upside Down",
    color = #FF9B5C,
    category = "Lanes",
    description = "The playfield turns over in one bar (and back). Place it on a bar without your notes.",
}

params {
    on = bool { from = "value1", default = true, label = "Upside down" },
}

function onEvent(p)
    local dur = beats(4)
    -- The fighters and the judgments shouldn't turn over too.
    hud.extras = false

    tween(hud.angle, p.on ? 180 : 0, dur, "cubicInOut")
    tween(camera.roll, p.on ? -180 : 0, dur, "cubicInOut")

    for lane = 0, 3 do
        -- Turned over, lane 0 would sit on the right: each lane moves to its mirror spot.
        tween(strum[lane].x, p.on ? (3 - 2 * lane) * strums.spacing : 0, dur, "cubicInOut")
        tween(strum[lane].angle, p.on ? -180 : 0, dur, "cubicInOut")
    end

    if not p.on then
        after(dur, function() hud.extras = true end)
    end
end
halo.event
format 1.1
-- Event Showcase 29/31: the lanes ride round in a ring like a carousel - the modchart's halo. The ones
-- at the back are smaller and fainter, so it reads as a ring seen from the front. Fall: the ring keeps
-- turning and the lanes drop off the screen one by one.
-- Shows: x / y / scale / alpha from one angle per lane, a ring centred on the screen however the lanes
-- are spaced.

event {
    name = "Halo",
    color = #FFE35C,
    category = "Lanes",
    description = "The lanes ride round in a ring. Fall = they drop off the screen from it.",
}

params {
    mode = choice { from = "value1", options = { "on", "fall", "off" }, label = "Mode" },
}

local mode = "off"
local onAt = 0
local fallAt = 0
local level = 0

function onEvent(p)
    if p.mode == "on" and mode == "off" then onAt = time end
    if p.mode == "fall" then fallAt = time end
    mode = p.mode
end

function onFrame(dt)
    if mode == "off" and level < 0.001 then return end

    level += ((mode == "off" ? 0 : 1) - level) * min(1, dt / 350)

    local s = strums.spacing
    local rx = s * 2.4
    local ry = s * 0.55
    -- One turn a bar.
    local turn = (time - onAt) / beats(4) * 2 * pi

    for lane = 0, 3 do
        -- Starts with lanes 0 and 1 on the left, 2 and 3 on the right.
        local ang = 2 * pi * lane / 4 - 0.75 * pi + turn
        -- 1 = at the front, -1 = at the back.
        local depth = cos(ang)
        local toMiddle = strum[lane].isDown ? -1 : 1
        local fall = 0

        if mode == "fall" then
            fall = pow(clamp((time - fallAt - beats(lane * 0.25)) / beats(3), 0, 1), 3) * screen.height * 1.3
        end

        -- Around the middle of the screen: undo the lane's own place, then the ring.
        strum[lane].x = level * (rx * sin(ang) - (lane - 1.5) * s)
        strum[lane].y = level * (ry * depth + toMiddle * ry) + fall
        strum[lane].scale = 1 - level * 0.2 * (1 - depth)
        strum[lane].alpha = 1 - level * 0.25 * (1 - depth)
    end

    if mode == "off" and level < 0.001 then
        for lane = 0, 3 do
            strum[lane].x = 0
            strum[lane].y = 0
            strum[lane].scale = 1
            strum[lane].alpha = 1
        end
    end
end
finale.event
format 1.1
-- Event Showcase 30/31: the ending.
-- Shows: reading the game live (player.score, player.accuracy, player.misses) in onFrame, round(),
-- fading the HUD, the strumline and its background, the "top" layer - the score stays readable while
-- the screen fades to black under it - and onEnd.

event {
    name = "Finale",
    color = #E2E8F0,
    category = "Text",
    description = "Fades the playfield, shows the live score and accuracy, and cuts to black at the very end.",
}

shared hype = 0

local active = false
local startTime = 0

function onEvent(p)
    active = true
    startTime = time
    hype = 0

    tween(hud.alpha, 0, beats(8), "sineInOut")
    tween(strums.alpha, 0.55, beats(8), "sineInOut")
    tween(underlay.alpha, 0, beats(8), "sineInOut")

    -- Layer "top": over the flash and screen colours, so the cut to black below doesn't hide it.
    text[0].layer = "top"
    text[1].layer = "top"

    text[0].value = "THAT'S ALL"
    text[0].x = 0.5
    text[0].y = 0.34
    text[0].angle = 0
    text[0].color = #FFFFFF
    text[0].alpha = 0
    text[0].size = 2
    tween(text[0].alpha, 1, beats(2))

    text[1].x = 0.5
    text[1].y = 0.44
    text[1].size = 0.9
    text[1].color = #FFE066
    text[1].alpha = 0
    tween(text[1].alpha, 1, beats(2))

    -- Cut to black over the last two beats of the song.
    local left = song.length - time
    after(left - beats(4), function()
        screen.color = #000000
        tween(screen.alpha, 1, beats(2), "quadIn")
    end)
end

function onFrame(dt)
    if not active then return end

    local accuracy = round(player.accuracy * 10) / 10
    text[1].value = "score " .. player.score .. "   accuracy " .. accuracy .. "%   misses " .. player.misses
end

function onEnd()
    log("showcase finished: score", player.score, "accuracy", player.accuracy, "misses", player.misses)
end
power_off.event
format 1.1
-- Event Showcase 31/31: the end - the old TV comes back and switches off. The picture squeezes into a
-- glowing line, the line into a dot, the dot fades out.
-- Shows: the same shader as Power On, played backwards, ending on screen.color.

event {
    name = "Power Off",
    color = #5CF2FF,
    category = "Screen",
    description = "The screen curves into an old TV and switches off into a dot (the collapse comes after one beat).",
}

function onEvent(p)
    shader[0].file = "crt.fsh"
    shader[0].amount = 1
    shader[0].a = 0
    shader[0].b = 1
    shader[0].c = 1
    shader[0].d = 0
    tween(shader[0].a, 1, beats(1), "sineOut")
    tween(shader[0].d, 1, beats(1), "sineOut")

    -- Pressed into a line (glowing brighter the thinner it gets), then into a dot.
    after(beats(1), function() tween(shader[0].c, 0, beats(0.4), "expoIn") end)
    after(beats(1.4), function() tween(shader[0].b, 0, beats(0.35), "expoIn") end)

    -- Black under the shader: the dot has nothing left to show and fades.
    after(beats(1.75), function()
        screen.color = #000000
        tween(screen.alpha, 1, beats(1))
    end)
end

The music

Two simple synth leads play the melodies: a hollow square wave for you, and a nasal pulse for the opponent. They're the song's two vocal tracks, so a miss mutes your lead.

The music, both leads, the chart and the logo were made with a script; the event files and the shaders are written by hand.