-- Level complete! Screen comes down
-- ! falls and is replaced by ?
-- Zoom for a bit until beat drop
-- At beat drop, gameboy screen cracks
-- Flashes through all 5 level select screens
-- Glitches into 6th level select screen
-- Glitch until you can't see the screen
-- Teleport

function onBegin()
	makeUnskippable()
	-- The same thing the other songs do (beam/particle effects, show collected coins)
	playSound("event:/CrossoverCollab/Xelk1/SFX/LevelComplete")
	setFlag("endCirclePre",true)
	wait(0.125)
	setFlag("endFadingBeams",true)
	wait(0.25)
	setFlag("endCircleA",true)
	wait(0.1)
	setFlag("endCirclePre",false)
	setFlag("endCircleB",true)
	wait(0.1)
	setFlag("endCircleC",true)
	wait(0.1)
	setFlag("endCircleParticlesA",true)
	setFlag("endFadingBeams",false)
	wait(0.1)
	setFlag("endCircleParticlesB",true)
	wait(0.1)
	setFlag("endCircleParticlesC",true)
	wait(0.05)
	setFlag("endCircleA",false)
	wait(0.1)
	setFlag("endCircleB",false)
	wait(0.1)
	setFlag("endCircleC",false)
	wait(0.25)
	setFlag("endCircleParticlesA",false)
	wait(0.1)
	setFlag("endCircleParticlesB",false)
	wait(0.1)
	setFlag("endCircleParticlesC",false)
	wait(0.65)
	setFlag("endSongCoinOutline",true)
	for i=1,3,1 do
		if getFlag("song5coin"..tostring(i)) then
			setFlag("song5coin"..tostring(i).."Display",true)
		end
	end
	
	wait(0.5) -- we wait a bit until the LevelComplete screen finishes "bouncing"
	
	-- interrogation thingy
	setFlag("LevelCompleteRaw",true)
	wait(3)
	setFlag("LevelCompleteInterrogation",true)
	wait(1.5)
	
	-- removes zoom
	setFlag("song5NoZoomout",true)

	-- screen cracks
	wait(1)
	setFlag("cracked",true)
	playSound("event:/CrossoverCollab/Xelk1/SFX/GlassCrack")
	wait(1)
	setFlag("crackedB",true)
	playSound("event:/CrossoverCollab/Xelk1/SFX/GlassBreak")
	wait(1.5)
	
	-- prepare to teleport and go through menus
	setColorGrade("none",true)
	setFlag("cracked",false)
	setFlag("crackedB",false)
	setFlag("GameboyEnd",true)
	setFlag("canSeeCoinsInSong5",true)
	setFlag("LevelCompleteInterrogation",false)
	
	setFlag("endFadingBeams",false)
	setFlag("endCirclePre",false)
	setFlag("endCircleA",false)
	setFlag("endCircleB",false)
	setFlag("endCircleC",false)
	setFlag("endCircleParticlesA",false)
	setFlag("endCircleParticlesB",false)
	setFlag("endCircleParticlesC",false)
	setFlag("endSongCoinOutline",false)
	setFlag("LevelCompleteRaw",false)
	for i=1,6,1 do
		for j=1,3,1 do
			setFlag("song"..tostring(i).."coin"..tostring(j).."Display",false)
		end
	end
	
	setFlag("MenuTransitionStartUD", true)
	wait(4.5)-- ultimate destruction menu
	--wait(0.5)
	--teleportTo(5876,5240,"song5") -- sonic blaster menu
	--wait(0.5)
	--teleportTo(6628,5240,"song5") -- battle jam menu
	--wait(0.5)
	--teleportTo(5524,5456,"song5") -- critical hit menu
	--wait(0.5)
	--teleportTo(5876,5456,"song5") -- how to adventure menu
	--wait(0.5)
	--teleportTo(6628,5456,"song5") -- finale menu
	--wait(0.5)
	--onEnd()
	--teleportTo(16,1472,"song6","Transition")
end

function onEnd()
	setFlag("MenuTransitionStartUD", false)
	setFlag("cracked",false)
	setFlag("crackedB",false)
	setFlag("endFadingBeams",false)
	setFlag("endCirclePre",false)
	setFlag("endCircleA",false)
	setFlag("endCircleB",false)
	setFlag("endCircleC",false)
	setFlag("endCircleParticlesA",false)
	setFlag("endCircleParticlesB",false)
	setFlag("endCircleParticlesC",false)
	setFlag("endSongCoinOutline",false)
	setFlag("LevelCompleteRaw",false)
	setFlag("canSeeCoinsInSong5",false)
	teleportTo(16,1472,"song6","Transition")
end