local excam = require("#Celeste.Mod.ExCameraDynamics.Code.Module.ExCameraInterop")
local badeline
local level = getLevel()

function onBegin()
	if getFlag("foolC",true) then
		disableMovement()
		disableRetry()
		setFlag("introCutsceneRunning",true)
		previousMusic = getMusic()
		wait(0.15)
		dash(0,-1)
		wait(0.05)
		dash(1,-1)
		waitUntilOnGround()
		wait(0.4)
		coroutine.yield(excam.Level_ZoomToFocus(getLevel(), vector2 (-19984,-2608), 1.2, 2))
		player.Facing = getEnum("Celeste.Facings", "Left")
		wait(0.5)
		playMusic("event:/CC/CC_BrutalOrchestra/CC_BO_IntroFull")
		player.DummyAutoAnimate = false
		player.Sprite:Play("lookUp")
		wait(1.8)
		player.DummyAutoAnimate = true
		wait(0.4)
		player.Facing = getEnum("Celeste.Facings", "Left")
		wait(0.3)
		
		level.Displacement:AddBurst(player.Position, 0, 8, 32, 0.5)
		coroutine.yield(player:CreateSplitParticles())
		badeline = celeste.BadelineDummy(player.Position + vector2(8, -10))
		badeline.Sprite.Scale = vector2(1, 1)
		level:Add(badeline)
		wait(0.2)
		player.Facing = getEnum("Celeste.Facings", "Right")
		playSound("event:/char/badeline/maddy_split", player.Position)
		coroutine.yield(badeline:FloatTo(player.Position + vector2(22, -18), 1, false, false, true))
		badeline.Sprite.Scale = vector2(-1, 1)
		wait(0.1)
		say("CC_Aques_intro02")
		
		playSound("event:/game/03_resort/suite_bad_exittop", player.Position)
		wait(0.2)
		coroutine.yield(badeline:FloatTo(player.Position + vector2(-18, -22), -1, false, false, false))
		wait(0.05)
		player.Facing = getEnum("Celeste.Facings", "Left")
		badeline.Sprite.Scale = vector2(1, 1)
		say("CC_Aques_intro02b")
		coroutine.yield(badeline:Vanish())
		coroutine.yield(excam.Level_ZoomBack(getLevel(), 0.6)) 
		wait(0.6)
		
	end
end

function onEnd()

	enableMovement()
	enableRetry()
	playMusic("previousMusic")
	setFlag("introCutsceneRunning",false)
	level:ResetZoom()
end

function dash(xVector, yVector)
  player.OverrideDashDirection = vector2(xVector, yVector)
  setPlayerState(2)
  wait(0.6)
  setPlayerState(11)
  player.OverrideDashDirection = nil
end