local monocle = require("#monocle")
local coroutineEntity = monocle.Entity()
local celeste = require("#celeste")

function onBegin()
		disableMovement()
		player.ForceCameraUpdate = true;
		local level = getLevel()
		local luanet = _G.luanet

		disableMovement()
		helpers.walkTo(603,false,1,true)
		wait(0.2)
		getLevel():add(coroutineEntity)
		level.Displacement:AddBurst(player.Position, 0.5, 8, 32, 0.5)
		coroutine.yield(player:CreateSplitParticles())
		badeline = celeste.BadelineDummy(player.Position + vector2(2, -8))
		badeline.Sprite.Scale = vector2(1, 1)
		level:Add(badeline)
		playSound("event:/char/badeline/maddy_split", player.Position)
		coroutine.yield(badeline:FloatTo(player.Position + vector2(40, -20), -1, true, true, true))
		wait(0.5)
		helpers.say("MtLabeur")		
		player.DummyAutoAnimate = false
		player.Sprite:Play("sleep")

		wait(2)
		helpers.say("Bonnenuit")	

		badeline:Vanish()
     		setFlag("fade", true)
		wait(1)
     		setFlag("musique", true)
     		setFlag("cauchemar", true)
     		setFlag("crepusculestop", true)
     		setFlag("stopla", true)
		wait(1)
     		setFlag("fade", false)

		level.Displacement:AddBurst(player.Position, 0.5, 8, 32, 0.5)
		coroutine.yield(player:CreateSplitParticles())
		badeline = celeste.BadelineDummy(player.Position + vector2(-2, -8))
		badeline.Sprite.Scale = vector2(1, 1)
		level:Add(badeline)
		playSound("event:/char/badeline/maddy_split", player.Position)
		coroutine.yield(badeline:FloatTo(player.Position + vector2(-30, -15), 1, true, true, true))
		helpers.say("Reveil")
		coroutine.yield(badeline:FloatTo(player.Position + vector2(17, -20), -1, true, true, true))
		helpers.say("PasReveil")
		coroutine.yield(badeline:FloatTo(player.Position + vector2(12, 0), -1, false, false, false))
		helpers.say("REVEILTOI")
     		setFlag("fade", true)
		wait(2)
		teleportTo (0,0,"cauch","WakeUp")
end

