local calc = require("#Monocle.Calc")
local dust = require("#Celeste.Dust")
local color = require("#Microsoft.Xna.Framework.Color")


function onBegin()
    disablePause()
	disableMovement()
    wait (1.5)
    run (40,false)
    player.DummyAutoAnimate = false
    player.Sprite:Play("roll")
	player.DummyFriction = false
	player.ForceCameraUpdate = true;

	local p = 0
	while p < 0.4 do
		player.Speed = vector2(calc.Approach(player.Speed.X, 0, 160 * engine.DeltaTime), player.Speed.Y)
    	wait(0)
		p = p + engine.DeltaTime
	end

    local q = 0
	while q < 1.1 do
		player.Speed = vector2(calc.Approach(player.Speed.X, -300, 160 * engine.DeltaTime), calc.Approach(player.Speed.Y, -30, 20 * engine.DeltaTime))
		wait(0)
        if player.Speed ~= 90 and engine.Scene:OnInterval(0.1) then
            dust.BurstFG(player.Position, -math.pi / 2, 2)
        end
		q = q + engine.DeltaTime
    end
    wait(2)
    playSound("event:/char/badeline/disappear")
    getLevel():Flash(color.White)
    player.DummyAutoAnimate = true
    player.Speed = vector2(0, player.Speed.Y)
    setPlayerState (17)
    setFlag("hstp6", true)
    -- instantTeleportTo(55193, -1638, "GCHeartSide_e0")
    endCutscene()
end