local vector2 = require("#microsoft.xna.framework.vector2")

local dummy

local function dummyFloatTo(dummy, x, y)
    coroutine.yield(dummy:FloatTo(vector2(x, y)))
end

function onBegin()
    if not getFlag("CS_cutscene_0") then
        player.Depth = 0
        setFlag("CS_cutscene_0", true)
        waitUntilOnGround()
        player.ForceCameraUpdate = true
        disableMovement()
        wait(0.6)
        walk(-5, false, 1)
        wait(0.6)
        walk(5, false, 1)
        wait(0.6)
        say("CS_start")
        wait(0.3)
        dummy = celeste.BadelineDummy(vector2(player.Position.X - 21, player.Position.Y - 8))
        engine.Scene:Add(dummy)
        dummyFloatTo(dummy, player.Position.X - 20, player.Position.Y - 8)
        wait(0.3)
        walk(-5, false, 1)
        say("CS_startA")
        dummy:Vanish()

        enableMovement()
    end
end

function onEnd(level, wasSkipped)
    if wasSkipped then
        if dummy then
            dummy:RemoveSelf()
        end
        player.Depth = 0
        enableMovement()
        setFlag("CS_cutscene_0", true)
    end
end