require "Undertale HP"

Arena.MoveToAndResize(320, -5, 640, 480, true, true)
NewAudio.CreateChannel("Song")
NewAudio.PlaySound("Song", "The World Revolving Metal Cover", false, 0.5)
NewAudio.Pause("Song")
SetPPCollision(true)
Player.lv = 1
Player.hp = 20
BlackD = CreateSprite("Pixel", "Top")
BlackD.color = {0,0,0}
BlackD.Scale(640, 480)
BlackD.MoveTo(320, 240)
BlackD.alpha = 0

tableaux = 0
timer = 0
PosX = 0
PosY = 0
ScreenRotation = 0
Empezar = 210

phases = {0, 0, 0}
Jevil = {}
BoxesJ = {}
Spades = {}
Hearts = {}
Clovers = {}
Balls = {}
Diamonds1 = {}
Diamonds2 = {}
SpadeCircles = {}
Carrousel = {}
DevilsKnife1 = {}
DevilsKnife2 = {}
DevilsKnife3 = {}

function Update()
	if not Pause then
		SongTime = NewAudio.GetPlayTime("Song")
		timer = timer + 1
		if timer > 60 and timer <= 90 then
			if not TituloSong then
				TituloSong = CreateSprite("Jevil Level/Song","Top")
				VersionLevel = CreateSprite("Jevil Level/Version","Top")
				Advice = CreateSprite("Advice "..GetAlMightyGlobal("Idioma"),"BelowPlayer")
				Advice.MoveTo(320, 240)
				VersionLevel.color = {0.5,0.5,0.5}
				Advice.color = {0.75,0.75,0.75}
			end
			TituloSong.MoveTo(579 - 100*math.sin(math.rad(90/30*(timer - 60))), 58)
			TituloSong.alpha = 1/30*(timer - 60)
			VersionLevel.MoveTo(-45.5 + 100*math.sin(math.rad(90/30*(timer - 60))), 17.5)
			VersionLevel.alpha = 1/30*(timer - 60)
			Advice.alpha = 1/30*(timer - 60)
		elseif timer == 105 then
			Start = true
		elseif timer > 210 and timer <= 240 then	
			if timer == 211 then
				NewAudio.Unpause("Song")
				SpawnMeter(207.65)
			end
			TituloSong.MoveTo(479 + 100/30*(timer - 210), 58)
			TituloSong.alpha = 1 - 1/30*(timer - 210)
			VersionLevel.MoveTo(54.5 - 100*math.sin(math.rad(90/30*(timer - 210))), 17.5)
			VersionLevel.alpha = 1 - 1/30*(timer - 210)
			Advice.alpha = 1 - 1/30*(timer - 210)
			if timer == 240 then
				TituloSong.Remove()
				TituloSong = nil
				VersionLevel.Remove()
				VersionLevel = nil
				Advice.Remove()
				Advice = nil
			end
		elseif timer > -720 and timer <= -660 then
			if not Black then
				Black = CreateSprite("Pixel", "Top")
				Black.MoveTo(320, 240)
				Black.Scale(640, 480)
				Black.color = {0,0,0}
			end
			Black.alpha = (timer + 720)/60
		elseif timer == -540 then
			Black.Remove()
			NewAudio.Stop("Song")
			NewAudio.DestroyChannel("Song")
			Start = nil
			RemoveAll()
			Encounter["nextwaves"] = {"MenuJ"}
			State("ACTIONSELECT")
			State("DEFENDING")
		end
		if Start then
			if not BG1 and NewAudio.GetPlayTime("Song") > 1.26 and not spawned then
				BG1 = CreateSprite("Jevil Level/BG","BelowPlayer")
				BG2 = CreateSprite("Jevil Level/BG","BelowPlayer")
				BG1.MoveTo(511.5, 240)
				BG2.MoveTo(1534.5, 240)
				BG1.color = {0,0,1}
				BG2.color = {0,0,1}
				BG1.alpha = 0
				BG2.alpha = 0
				spawned = true
			elseif BG1 then
				BG1.MoveTo(BG1.x - 4, 240)
				BG2.MoveTo(BG2.x - 4, 240)
				if BG1.x <= -511.5 then
					BG1.MoveTo(BG1.x + 2046, 240)
				end
				if BG2.x <= -511.5 then
					BG2.MoveTo(BG2.x + 2046, 240)
				end
				if NewAudio.GetPlayTime("Song") <= 182.14 then
					BG1.alpha = math.min(BG1.alpha + 0.005, 0.2)
					BG2.alpha = math.min(BG2.alpha + 0.005, 0.2)
				else
					BG1.alpha = BG1.alpha - 0.005
					BG2.alpha = BG2.alpha - 0.005
					if BG1.alpha <= 0 then
						BG1.Remove()
						BG2.Remove()
						BG1 = nil
						BG2 = nil
					end
				end
			end
			if NewAudio.GetPlayTime("Song") >= 0 and phases[1] == 0 then
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(684, 264), Type = "Spades", Explode = 0.15})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(820, 400), Type = "Spades", Explode = 0.62})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(684, 264), Type = "Spades", Explode = 0.15})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(820, 400), Type = "Spades", Explode = 0.62})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(916, 496), Type = "Spades", Explode = 1.03})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = math.random(952, 532), Type = "Spades", Explode = 1.18})
				phases[1] = 1
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 1.11 and phases[1] == 1 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 2
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 1.61 and phases[1] == 2 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 3
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 2.11 and phases[1] == 3 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 4
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 2.61 and phases[1] == 4 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 5
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 3.77 and phases[1] == 5 then
				table.insert(SpadeCircles, {Bullets = {CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0)}, X = PosX, Y = PosY, Rotation = math.random(360)})
				phases[1] = 6
			elseif NewAudio.GetPlayTime("Song") > 6.05 and phases[1] == 6 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 7
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 6.55 and phases[1] == 7 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 8
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 7.05 and phases[1] == 8 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 9
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 7.55 and phases[1] == 9 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 10
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 8.81 and phases[1] == 10 then
				if NewAudio.GetPlayTime("Song") <= 10.54 and timer%2 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 10.54 then
					phases[1] = 11
				end
			elseif NewAudio.GetPlayTime("Song") > 11.43 and phases[1] == 11 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 12
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 11.93 and phases[1] == 12 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 13
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 12.43 and phases[1] == 13 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 14
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 12.93 and phases[1] == 14 then
				repeat
					tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
					if tabla.X == 1 then
						tabla.Direction = "R"
						tabla.X = math.random(-290, 0)
					else
						tabla.Direction = "L"
						tabla.X = math.random(290, 0)
					end
					if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
						tabla.Sprite.Remove()
					end
				until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
				table.insert(Jevil, tabla)
				phases[1] = 15
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 13.88 and phases[1] == 15 then
				table.insert(SpadeCircles, {Bullets = {CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0)}, X = PosX, Y = PosY, Rotation = math.random(360)})
				phases[1] = 16
			elseif NewAudio.GetPlayTime("Song") > 13.88 and phases[1] == 16 then
				if NewAudio.GetPlayTime("Song") <= 15.61 and timer%12 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 15.61 then
					phases[1] = 17
				end
			elseif NewAudio.GetPlayTime("Song") > 16.5 and phases[1] == 17 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 18
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 17 and phases[1] == 18 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 19
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 17.5 and phases[1] == 19 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 20
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 18 and phases[1] == 20 then
				for i=1,2 do
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				end
				phases[1] = 21
				tabla = nil
			elseif NewAudio.GetPlayTime("Song") > 18.95 and phases[1] == 21 then
				for i=1,4 do
					local randomizador = math.random(2)
					for j=1,5 do
						if j%2 == 0 then
							table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "R", Vel = 1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 45*i, TimerX = -90 + 45*i, Aparecer = 21.46, Desaparecer = 31.56})
							table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "R", Vel = 1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 180 + 45*i, TimerX = 90 + 45*i, Aparecer = 21.46, Desaparecer = 31.56})
						else
							table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "R", Vel = 1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 45*i, TimerX = -90 + 45*i, Aparecer = 21.46, Desaparecer = 41.68})
							table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "R", Vel = 1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 180 + 45*i, TimerX = 90 + 45*i, Aparecer = 21.46, Desaparecer = 41.68})
						end
					end
				end
				phases[1] = 22
			elseif NewAudio.GetPlayTime("Song") > 19.3 and phases[1] == 22 then
				if math.random(2) == 1 then
					Audio.PlaySound("chaos CHAOS")
				else
					Audio.PlaySound("I can do anything")
				end
				phases[1] = 23
			elseif NewAudio.GetPlayTime("Song") > 20.72 and phases[1] == 23 then
				Audio.PlaySound("ueeueeueeuee")
				phases[1] = 24
			elseif NewAudio.GetPlayTime("Song") > 31 and phases[1] == 24 then
				Audio.PlaySound("DevilsKnife")
				phases[1] = 25
			elseif NewAudio.GetPlayTime("Song") > 31.5 + 1.5*(phases[1] - 25) and phases[1] >= 25 and phases[1] <= 31 then
				local inirot = math.random(360)
				local inidir = math.random(2)
				for i=1,4 do
					table.insert(DevilsKnife1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), Rotation = inirot + 90*i, Direction = inidir})
				end
				phases[1] = phases[1] + 1
			elseif NewAudio.GetPlayTime("Song") > 41.68 and phases[1] == 32 then
				if NewAudio.GetPlayTime("Song") <= 50 and timer%30 == 0 then
					local randomizador = math.random(4)
					if randomizador == 1 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Spades", Altura = math.random(210, -210)})
					elseif randomizador == 2 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Heart 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Hearts", Altura = math.random(210, -210)})
					elseif randomizador == 3 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Clover 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Clovers", Altura = math.random(210, -210)})
					else
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Diamond 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Diamonds", Altura = math.random(210, -210)})
					end
				elseif NewAudio.GetPlayTime("Song") > 50 then
					Audio.PlaySound("HAHAHAHA")
					phases[1] = 33
				end
			elseif NewAudio.GetPlayTime("Song") > 50 and phases[1] == 33 then
				if NewAudio.GetPlayTime("Song") <= 60 and timer%50 == 0 then
					local randomizador = math.random(4)
					if randomizador == 1 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Spades", Altura = math.random(210, -210)})
					elseif randomizador == 2 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Heart 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Hearts", Altura = math.random(210, -210)})
					elseif randomizador == 3 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Clover 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Clovers", Altura = math.random(210, -210)})
					else
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Diamond 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Diamonds", Altura = math.random(210, -210)})
					end
				elseif NewAudio.GetPlayTime("Song") > 60 then
					Audio.PlaySound("ueeueeueeuee")
					phases[1] = 34
				end
			elseif NewAudio.GetPlayTime("Song") > 61.4 and phases[1] == 34 then
				if not contador then
					contador = 0
				end
				if NewAudio.GetPlayTime("Song") > 61.4 + 0.63*contador then
					table.insert(Clovers, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 2", 0, 0), X = math.random(-300, 300), Y = math.random(-220, 220)})
					contador = contador + 1
				elseif NewAudio.GetPlayTime("Song") > 79 then
					phases[1] = 35
					contador = nil
				end
			elseif NewAudio.GetPlayTime("Song") > 81 and phases[1] == 35 then
				if NewAudio.GetPlayTime("Song") <= 101 and timer%10 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 101 then
					phases[1] = 36
				end
			elseif NewAudio.GetPlayTime("Song") > 102 and phases[1] == 36 then
				if not contador then
					contador = 0
				end
				if NewAudio.GetPlayTime("Song") > 102.13 + 0.75*contador and contador <= 2 then
					local tipo = "Spades"
					for i=1,2 do
						repeat
							tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = tipo}
							if tabla.X == 1 then
								tabla.Direction = "R"
								tabla.X = math.random(-290, 0)
							else
								tabla.Direction = "L"
								tabla.X = math.random(290, 0)
							end
							if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
								tabla.Sprite.Remove()
							end
						until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
						table.insert(Jevil, tabla)
						tipo = "Diamond"
					end
					contador = contador + 1
				elseif NewAudio.GetPlayTime("Song") > 104.83 and contador > 2 then
					table.insert(SpadeCircles, {Bullets = {CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0)}, X = PosX, Y = PosY, Rotation = math.random(360)})
					phases[1] = 37
					contador = nil
				end
			elseif NewAudio.GetPlayTime("Song") > 104.83 and phases[1] == 37 then
				if NewAudio.GetPlayTime("Song") <= 106.34 and timer%12 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 106.34 then
					phases[1] = 38
				end
			elseif NewAudio.GetPlayTime("Song") > 106.5 and phases[1] == 38 then
				if not contador then
					contador = 0
				end
				if NewAudio.GetPlayTime("Song") > 106.94 + 0.75*contador and contador <= 2 then
					local tipo = "Spades"
					for i=1,2 do
						repeat
							tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = tipo}
							if tabla.X == 1 then
								tabla.Direction = "R"
								tabla.X = math.random(-290, 0)
							else
								tabla.Direction = "L"
								tabla.X = math.random(290, 0)
							end
							if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
								tabla.Sprite.Remove()
							end
						until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
						table.insert(Jevil, tabla)
						tipo = "Diamond"
					end
					contador = contador + 1
				elseif NewAudio.GetPlayTime("Song") > 109.88 and contador > 2 then
					local inirot = math.random(360)
					local inidir = math.random(2)
					for i=1,4 do
						table.insert(DevilsKnife1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), Rotation = inirot + 90*i, Direction = inidir})
					end
					phases[1] = 39
					contador = nil
				end
			elseif NewAudio.GetPlayTime("Song") > 112.23 and phases[1] == 39 then
				if not contador then
					contador = 0
				end
				if NewAudio.GetPlayTime("Song") > 112.23 + 0.75*contador and contador <= 2 then
					local tipo = "Spades"
					for i=1,2 do
						repeat
							tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = tipo}
							if tabla.X == 1 then
								tabla.Direction = "R"
								tabla.X = math.random(-290, 0)
							else
								tabla.Direction = "L"
								tabla.X = math.random(290, 0)
							end
							if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
								tabla.Sprite.Remove()
							end
						until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
						table.insert(Jevil, tabla)
						tipo = "Diamond"
					end
					contador = contador + 1
				elseif NewAudio.GetPlayTime("Song") > 114.94 and contador > 2 then
					local inirot = math.random(360)
					local inidir = math.random(2)
					for i=1,4 do
						table.insert(DevilsKnife1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), Rotation = inirot + 90*i, Direction = inidir})
					end
					phases[1] = 40
					contador = nil
				end
			elseif NewAudio.GetPlayTime("Song") > 114.94 and phases[1] == 40 then
				if NewAudio.GetPlayTime("Song") <= 116.96 and timer%6 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 116.96 then
					phases[1] = 41
				end
			elseif NewAudio.GetPlayTime("Song") > 117.05 and phases[1] == 41 then
				if not contador then
					contador = 0
				end
				if NewAudio.GetPlayTime("Song") > 117.05 + 0.75*contador and contador <= 2 then
					local tipo = "Spades"
					for i=1,2 do
						repeat
							tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = tipo}
							if tabla.X == 1 then
								tabla.Direction = "R"
								tabla.X = math.random(-290, 0)
							else
								tabla.Direction = "L"
								tabla.X = math.random(290, 0)
							end
							if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
								tabla.Sprite.Remove()
							end
						until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
						table.insert(Jevil, tabla)
						tipo = "Diamond"
					end
					contador = contador + 1
				elseif NewAudio.GetPlayTime("Song") > 119.99 and contador > 2 then
					for i=1,8 do
						local randomizador = math.random(2)
						for j=1,5 do
							if j%2 == 0 then
								table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "L", Vel = -1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 45*i, TimerX = -45*i, Aparecer = 122.52, Desaparecer = 132.62})
							else
								table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "L", Vel = -1.5, Y = 200 - 100*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 45*i, TimerX = -45*i, Aparecer = 122.52, Desaparecer = 142.87})
							end
						end
					end
					if math.random(2) == 1 then
						Audio.PlaySound("chaos CHAOS")
					else
						Audio.PlaySound("I can do anything")
					end
					Index1 = CreateSprite("Pixel", "BelowPlayer")
					Index2 = CreateSprite("Pixel", "BelowPlayer")
					Index1.Scale(900, 6)
					Index2.Scale(6, 900)
					Index1.MoveTo(320, 240)
					Index2.MoveTo(320, 240)
					Index1.alpha = 0
					Index2.alpha = 0
					phases[1] = 42
					contador = nil
				end
			elseif NewAudio.GetPlayTime("Song") > 121.41 and phases[1] == 42 then
				Audio.PlaySound("HAHAHAHA")
				phases[1] = 43
			elseif NewAudio.GetPlayTime("Song") > 122.52 and phases[1] == 43 then
				if NewAudio.GetPlayTime("Song") <= 142.87 then
					ScreenRotation = 20*math.sin(math.rad(90*(NewAudio.GetPlayTime("Song") - 122.52)))
				else
					phases[1] = 44
				end
			elseif NewAudio.GetPlayTime("Song") > 142.87 and phases[1] == 44 then
				if NewAudio.GetPlayTime("Song") <= 162.94 then
					ScreenRotation = 10.14 + 889.86/20.07*(NewAudio.GetPlayTime("Song") - 142.87)
				else
					ScreenRotation = 180
					phases[1] = 45
				end
			elseif NewAudio.GetPlayTime("Song") > 162.94 and phases[1] == 45 then
				if NewAudio.GetPlayTime("Song") <= 180.14 then
					ScreenRotation = 180 + 20*math.sin(math.rad(90*(NewAudio.GetPlayTime("Song") - 162.94)))
				else
					phases[1] = 46
				end
			elseif NewAudio.GetPlayTime("Song") > 180.14 and phases[1] == 46 then
				if NewAudio.GetPlayTime("Song") <= 183.14 then
					if NewAudio.GetPlayTime("Song") > 181.14 and not devil then
						Audio.PlaySound("DevilsKnife")
						devil = true
					elseif NewAudio.GetPlayTime("Song") > 182.14 and not said then
						Audio.PlaySound("bye bye")
						said = true
					end
					ScreenRotation = 199.13/2 + 199.13/2*math.cos(math.rad(180/3*(NewAudio.GetPlayTime("Song") - 180.14)))
				else
					RemoveIndexes = true
					ScreenRotation = 0
					phases[1] = 47
				end
			elseif NewAudio.GetPlayTime("Song") > 183.14 and phases[1] == 47 then
				if not rapidez then
					rapidez = 50
				end
				if NewAudio.GetPlayTime("Song") <= 192.82 and (timer - 240)%rapidez == 0 then
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -360 + 90*math.random(7), Y = 300}
					tabla.Bullet.sprite.Scale(2, 2)
					table.insert(DevilsKnife3, tabla)
					rapidez = math.max(rapidez - 3, 20)
					timer = 240
				elseif NewAudio.GetPlayTime("Song") > 192.82 then
					Audio.PlaySound("NEO chaos")
					timer = 240
					phases[1] = 48
				end
			elseif NewAudio.GetPlayTime("Song") > 192.82 and phases[1] == 48 then
				if NewAudio.GetPlayTime("Song") <= 202.84 and timer%10 == 0 then
					repeat
						randomizador = math.random(7)
					until not old or (old ~= randomizador and old ~= randomizador + 1 and old ~= randomizador - 1)
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -360 + 90*randomizador, Y = 300}
					tabla.Bullet.sprite.Scale(2, 2)
					table.insert(DevilsKnife3, tabla)
					old = randomizador
					if NewAudio.GetPlayTime("Song") <= 201.34 then
						table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
					end
				elseif NewAudio.GetPlayTime("Song") > 202.84 then
					timer = -1000
					phases[1] = 49
				end
			end
			if NewAudio.GetPlayTime("Song") > 31.5 and phases[2] == 0 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = 120, Direction = "R"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = -120, Direction = "R"})
				end
				phases[2] = 1
			elseif NewAudio.GetPlayTime("Song") > 34 and phases[2] == 1 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = 120, Direction = "L"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = -120, Direction = "L"})
				end
				phases[2] = 2
			elseif NewAudio.GetPlayTime("Song") > 36.5 and phases[2] == 2 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = 120, Direction = "R"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = -120, Direction = "R"})
				end
				phases[2] = 3
			elseif NewAudio.GetPlayTime("Song") > 39 and phases[2] == 3 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = 120, Direction = "L"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = -120, Direction = "L"})
				end
				phases[2] = 4
			elseif NewAudio.GetPlayTime("Song") > 51.84 and phases[2] == 4 then
				if NewAudio.GetPlayTime("Song") <= 61 and timer%20 == 0 then
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Diamond"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				elseif NewAudio.GetPlayTime("Song") > 61 then
					phases[2] = 5
				end
			elseif NewAudio.GetPlayTime("Song") > 61 and phases[2] == 5 then
				if NewAudio.GetPlayTime("Song") <= 81 and timer%45 == 0 then
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Diamond"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				elseif NewAudio.GetPlayTime("Song") > 80 then
					phases[2] = 6
				end
			elseif NewAudio.GetPlayTime("Song") > 109.38 and phases[2] == 6 then
				if NewAudio.GetPlayTime("Song") <= 110.89 and timer%30 == 0 then
					local randomizador = math.random(4)
					if randomizador == 1 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Spades", Altura = math.random(210, -210)})
					elseif randomizador == 2 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Heart 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Hearts", Altura = math.random(210, -210)})
					elseif randomizador == 3 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Clover 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Clovers", Altura = math.random(210, -210)})
					else
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Diamond 2","BelowPlayer"), X = math.random(-260, 260), Y = 264, Type = "Diamonds", Altura = math.random(210, -210)})
					end
				elseif NewAudio.GetPlayTime("Song") > 110.89 then
					phases[2] = 7
				end
			elseif NewAudio.GetPlayTime("Song") > 116.36 and phases[2] == 7 then
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = 0, Y = 264, Type = "Spades", Altura = 0})
				phases[2] = 8
			elseif NewAudio.GetPlayTime("Song") > 132.62 and phases[2] == 8 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = 120, Direction = "L"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = -120, Direction = "L"})
				end
				if math.random(2) == 1 then
					Audio.PlaySound("ueeueeueeuee")
				else
					Audio.PlaySound("HAHAHAHA")
				end
				phases[2] = 9
			elseif NewAudio.GetPlayTime("Song") > 135.12 and phases[2] == 9 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = 120, Direction = "R"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = -120, Direction = "R"})
				end
				phases[2] = 10
			elseif NewAudio.GetPlayTime("Song") > 137.62 and phases[2] == 10 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = 120, Direction = "L"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = 320, Y = -120, Direction = "L"})
				end
				phases[2] = 11
			elseif NewAudio.GetPlayTime("Song") > 140.12 and phases[2] == 11 then
				if PosY > 0 then
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = 120, Direction = "R"})
				else
					table.insert(DevilsKnife2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Knife", 0, 0), X = -320, Y = -120, Direction = "R"})
				end
				phases[2] = 12
			elseif NewAudio.GetPlayTime("Song") > 142.87 and phases[2] == 12 then
				if NewAudio.GetPlayTime("Song") <= 160.94 and timer%50 == 0 then
					local randomizador = math.random(4)
					if randomizador == 1 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = math.random(-260, 260), Y = 350, Type = "Spades", Altura = math.random(210, -210)})
					elseif randomizador == 2 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Heart 2","BelowPlayer"), X = math.random(-260, 260), Y = 350, Type = "Hearts", Altura = math.random(210, -210)})
					elseif randomizador == 3 then
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Clover 2","BelowPlayer"), X = math.random(-260, 260), Y = 350, Type = "Clovers", Altura = math.random(210, -210)})
					else
						table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Diamond 2","BelowPlayer"), X = math.random(-260, 260), Y = 350, Type = "Diamonds", Altura = math.random(210, -210)})
					end
				elseif NewAudio.GetPlayTime("Song") > 160.94 then
					Audio.PlaySound("ueeueeueeuee")
					phases[2] = 13
				end
			elseif NewAudio.GetPlayTime("Song") > 162.94 and phases[2] == 13 then
				if NewAudio.GetPlayTime("Song") <= 181.14 and timer%10 == 0 then
					table.insert(Diamonds2, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 2", 0, 0), X = math.random(-310, 310), Y = -200})
				elseif NewAudio.GetPlayTime("Song") > 181.14 then
					phases[2] = 14
				end
			elseif NewAudio.GetPlayTime("Song") > 202.1 and phases[2] == 14 then
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Diamond 2","BelowPlayer"), X = 0, Y = 264, Type = "Diamonds", Altura = 0})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Clover 2","BelowPlayer"), X = 0, Y = 264, Type = "Clovers", Altura = 0})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Heart 2","BelowPlayer"), X = 0, Y = 264, Type = "Hearts", Altura = 0})
				table.insert(BoxesJ, {Sprite = CreateSprite("Jevil Level/Bullets/Boxes/Spade 2","BelowPlayer"), X = 0, Y = 264, Type = "Spades", Altura = 0})
				phases[2] = 15
			end
			if NewAudio.GetPlayTime("Song") > 80 and phases[3] == 0 then
				for i=1,4 do
					local randomizador = math.random(2)
					for j=1,4 do
						table.insert(Carrousel, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Carousel 1 L", 0, 0, "BelowPlayer"), Direction = "R", Vel = 1.5, Y = 200 - 125*(j - 1), Alpha = 0, Color = {0.5,0.5,0.5}, Type = randomizador, Fun = math.random(100), Movimiento = 40, Timer = 180*i, TimerX = 90*i, Aparecer = 82.1, Desaparecer = 102})
					end
				end
				Audio.PlaySound("I can do anything")
				phases[3] = 1
			elseif NewAudio.GetPlayTime("Song") > 162.94 and phases[3] == 1 then
				if NewAudio.GetPlayTime("Song") <= 181.14 and timer%60 == 0 then
					repeat
						tabla = {Sprite = CreateSprite("Jevil Level/Jevil/Waiting L","BelowPlayer"), X = math.random(2), Y = math.random(-210, 210), Type = "Spades"}
						if tabla.X == 1 then
							tabla.Direction = "R"
							tabla.X = math.random(-290, 0)
						else
							tabla.Direction = "L"
							tabla.X = math.random(290, 0)
						end
						if tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250 then
							tabla.Sprite.Remove()
						end
					until not (tabla.X >= PosX - 250 and tabla.X <= PosX + 250 and tabla.Y >= PosY - 250 and tabla.Y <= PosY + 250)
					table.insert(Jevil, tabla)
				elseif NewAudio.GetPlayTime("Song") > 181.14 then
					phases[3] = 2
				end
			end
		end
		if Index1 and Index2 then
			Index1.rotation = ScreenRotation
			Index2.rotation = ScreenRotation
			if not RemoveIndexes and Index1.alpha < 0.5 then
				Index1.alpha = Index1.alpha + 0.01
				Index2.alpha = Index2.alpha + 0.01
			else
				Index1.alpha = Index1.alpha - 0.01
				Index2.alpha = Index2.alpha - 0.01
			end
			if Index1.alpha <= 0 then
				Index1.Remove()
				Index2.Remove()
				Index1 = nil
				Index2 = nil
			end
		end
		for i=1,#DevilsKnife3 do
			local Datos = DevilsKnife3[i - tableaux]
			if not Datos.Direction then
				Datos.Direction = 24 - 16*math.random(2)
			end
			Datos.Y = Datos.Y - 12
			if Datos.Y <= -210 and not Datos.Rayo then
				Datos.Rayo = CreateProjectileAbs("Pixel", 320 + Datos.X, 240)
				Datos.Rayo.sprite.Scale(0, 480)
				Audio.PlaySound("impact")
			end
			if Datos.Rayo then
				Datos.Rayo.sprite.Scale(120*math.sin(math.rad(180/45*((Datos.Y + 210)/-4))), 480)
			end
			Datos.Bullet.sprite.rotation = Datos.Bullet.sprite.rotation + Datos.Direction
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Y <= -390 then
				Datos.Rayo.Remove()
				Datos.Bullet.Remove()
				table.remove(DevilsKnife3, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#DevilsKnife2 do
			local Datos = DevilsKnife2[i - tableaux]
			if not Datos.Timer then
				Datos.Timer = 0
			end
			Datos.Timer = Datos.Timer + 1
			if Datos.Timer <= 30 then
				if Datos.Direction == "R" then
					Datos.Rotation = -90/30*Datos.Timer
				else
					Datos.Rotation = 180 - 90/30*Datos.Timer
				end
				Datos.Bullet.sprite.alpha = 1/30*Datos.Timer
			elseif Datos.Timer <= 150 then
				if Datos.Direction == "R" then
					Datos.X = -320 + 640/120*(Datos.Timer - 30)
				else
					Datos.X = 320 - 640/120*(Datos.Timer - 30)
				end
			elseif Datos.Timer > 150 then
				Datos.Bullet.sprite.alpha = 1 - 1/20*(Datos.Timer - 150)
			end
			Datos.Bullet.sprite.Scale(3, 3)
			Datos.Bullet.sprite.color = {1,0,0}
			Datos.Bullet.sprite.rotation = ScreenRotation + Datos.Rotation
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Timer >= 170 then
				Datos.Bullet.Remove()
				table.remove(DevilsKnife2, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#DevilsKnife1 do
			local Datos = DevilsKnife1[i - tableaux]
			if not Datos.Aux then
				Datos.Aux = {}
			end
			if not Datos.Distancia then
				Datos.Distancia = 150
			end
			if not Datos.Timer then
				Datos.Timer = 0
			end
			Datos.Timer = Datos.Timer + 1
			if Datos.Timer <= 60 then
				Datos.Bullet.sprite.alpha = 1/60*Datos.Timer
				Datos.Aux.X = PosX
				Datos.Aux.Y = PosY
			else
				Datos.Distancia = 150*math.cos(math.rad((Datos.Timer - 60)*2))
				if Datos.Timer > 120 then
					Datos.Bullet.sprite.alpha = 1 - 1/20*(Datos.Timer - 120)
				end
			end
			Datos.Rotation = Datos.Rotation + 2*(-3 + 2*Datos.Direction)
			Datos.X = Datos.Aux.X + Datos.Distancia*math.cos(math.rad(Datos.Rotation))
			Datos.Y = Datos.Aux.Y + Datos.Distancia*math.sin(math.rad(Datos.Rotation))
			Datos.Bullet.sprite.rotation = Datos.Bullet.sprite.rotation + 8*(-3 + 2*Datos.Direction)
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Timer >= 140 then
				Datos.Bullet.Remove()
				table.remove(DevilsKnife1, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Carrousel do
			local Datos = Carrousel[i - tableaux]
			if not Datos.Status then
				Datos.Status = "Front"
			end
			if not Datos.Aux then
				Datos.Aux = Datos.Y
			end
			if Datos.Fun == 24 then
				Datos.Type = 3
			end
			Datos.Timer = Datos.Timer + 4
			Datos.TimerX = Datos.TimerX + Datos.Vel
			if NewAudio.GetPlayTime("Song") > Datos.Aparecer then
				if Datos.TimerX%360 > 270 or Datos.TimerX%360 <= 90 then
					Datos.Color = {1,1,1}
					Datos.Bullet.SetVar("No Damage", nil)
					Datos.Bullet.sprite.layer = "BelowBullet"
				else
					Datos.Color = {0.33,0.33,0.33}
					Datos.Bullet.SetVar("No Damage", true)
					Datos.Bullet.sprite.layer = "BelowPlayer"
				end
				Datos.Bullet.sprite.Scale(1 + 0.1*math.sin(math.rad(math.min(180/0.2*(NewAudio.GetPlayTime("Song") - Datos.Aparecer), 180))), 1 + 0.1*math.sin(math.rad(math.min(180/0.2*(NewAudio.GetPlayTime("Song") - Datos.Aparecer), 180))))
				if NewAudio.GetPlayTime("Song") > Datos.Desaparecer then
					Datos.Alpha = Datos.Alpha - 0.04
				end
			else
				if Datos.TimerX%360 > 270 or Datos.TimerX%360 <= 90 then
					Datos.Color = {0.6,0.6,0.6}
					Datos.Bullet.SendToTop()
					Datos.Bullet.sprite.layer = "BelowPlayer"
				else
					Datos.Color = {0.2,0.2,0.2}
				end
				Datos.Bullet.SetVar("No Damage", true)
			end
			if Datos.Alpha < 1 and NewAudio.GetPlayTime("Song") <= Datos.Desaparecer then
				Datos.Alpha = Datos.Alpha + 0.01
			end
			if Datos.TimerX%360 > 270 or Datos.TimerX%360 <= 90 then
				if Datos.Direction == "R" then
					Datos.Bullet.sprite.Set("Jevil Level/Bullets/Carousel "..Datos.Type.." R")
				else
					Datos.Bullet.sprite.Set("Jevil Level/Bullets/Carousel "..Datos.Type.." L")
				end
				Datos.Bullet.sprite.xscale = math.cos(math.rad(Datos.TimerX))
			else
				if Datos.Direction == "R" then
					Datos.Bullet.sprite.Set("Jevil Level/Bullets/Carousel "..Datos.Type.." L")
				else
					Datos.Bullet.sprite.Set("Jevil Level/Bullets/Carousel "..Datos.Type.." R")
				end
				Datos.Bullet.sprite.xscale = -math.cos(math.rad(Datos.TimerX))
			end
			Datos.X = 320*math.sin(math.rad(Datos.TimerX))
			Datos.Y = Datos.Aux + Datos.Movimiento*math.sin(math.rad(Datos.Timer))
			Datos.Bullet.sprite.alpha = Datos.Alpha
			Datos.Bullet.sprite.color = Datos.Color
			Datos.Bullet.sprite.rotation = ScreenRotation
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Alpha <= 0 then
				Datos.Bullet.Remove()
				table.remove(Carrousel, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Jevil do
			local Datos = Jevil[i - tableaux]
			if not Datos.Timer then
				Datos.Timer = 0
			end
			Datos.Timer = Datos.Timer + 1
			if Datos.Timer <= 15 then
				Datos.Sprite.Set("Jevil Level/Jevil/Waiting "..Datos.Direction)
				Datos.Sprite.Scale(1/15*Datos.Timer, 1)
			elseif Datos.Timer == 40 then
				Datos.Sprite.Set("Jevil Level/Jevil/Throwing "..Datos.Direction)
				if Datos.Type == "Spades" then
					local angl = math.atan2(PosX - Datos.X, PosY - Datos.Y)/math.pi*180*-1+90
					while angl >= 360 do
						angl = angl - 360
					end
					while angl < 0 do
						angl = angl + 360
					end
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y + 4, Rotation = angl - 30, Vel = 4}
					tabla.Bullet.sprite.Scale(0.5, 0.5)
					table.insert(Spades, tabla)
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y + 4, Rotation = angl - 15, Vel = 4}
					tabla.Bullet.sprite.Scale(0.5, 0.5)
					table.insert(Spades, tabla)
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y + 4, Rotation = angl, Vel = 4}
					tabla.Bullet.sprite.Scale(0.5, 0.5)
					table.insert(Spades, tabla)
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y + 4, Rotation = angl + 15, Vel = 4}
					tabla.Bullet.sprite.Scale(0.5, 0.5)
					table.insert(Spades, tabla)
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y + 4, Rotation = angl + 30, Vel = 4}
					tabla.Bullet.sprite.Scale(0.5, 0.5)
					table.insert(Spades, tabla)
				elseif Datos.Type == "Diamond" then
					local tabla = {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y + 4, Vel = 6}
					tabla.Bullet.sprite.Scale(0.75, 0.75)
					table.insert(Diamonds1, tabla)
				end
				Audio.PlaySound("OH")
			elseif Datos.Timer > 55 then
				Datos.Sprite.Scale(1 - 1/15*(Datos.Timer - 55), 1 + 0.5/15*(Datos.Timer - 55))
			end
			Datos.Sprite.rotation = ScreenRotation
			Datos.Sprite.MoveTo(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Timer == 70 then
				Datos.Sprite.Remove()
				table.remove(Jevil, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#BoxesJ do
			local Datos = BoxesJ[i - tableaux]
			if Datos.Sprite then
				Datos.Y = Datos.Y - 4
				Datos.Sprite.color = {0.5, 0.5, 0.5}
				Datos.Sprite.rotation = ScreenRotation
				Datos.Sprite.MoveTo(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
				if Datos.Explode then
					if NewAudio.GetPlayTime("Song") > Datos.Explode then
						if Datos.Type == "Spades" then
							local inirot = math.random(360)
							for i=1,12 do
								table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = inirot, Vel = 4})
								inirot = inirot%360 + 30
							end
						elseif Datos.Type == "Hearts" then
							table.insert(Hearts, {Bullets = {CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0)}, X = Datos.X, Y = Datos.Y, Angulo = math.random(360), Vel = 4})
						elseif Datos.Type == "Clovers" then
							local angl = math.atan2(PosX - Datos.X, PosY - Datos.Y)/math.pi*180*-1+90
							while angl >= 360 do
								angl = angl - 360
							end
							while angl < 0 do
								angl = angl + 360
							end
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl - 20, Vel = 4})
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl, Vel = 4})
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl + 20, Vel = 4})
						elseif Datos.Type == "Diamonds" then
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 5})
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 4.5})
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 4})
						end
						Datos.Timer = 0
						Datos.Circle = CreateSprite("Jevil Level/Bullets/Explotion","BelowPlayer")
						Datos.Circle.Scale(0, 0)
						Datos.Circle.MoveTo(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
						Datos.Sprite.Remove()
						Datos.Sprite = nil
					elseif NewAudio.GetPlayTime("Song") > Datos.Explode - 0.6 and not Datos.Animated then
						if Datos.Type == "Spades" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Spade 1","Jevil Level/Bullets/Boxes/Spade 2"}, 0.1)
						elseif Datos.Type == "Hearts" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Heart 1","Jevil Level/Bullets/Boxes/Heart 2"}, 0.1)
						elseif Datos.Type == "Clovers" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Clover 1","Jevil Level/Bullets/Boxes/Clover 2"}, 0.1)
						elseif Datos.Type == "Diamonds" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Diamond 1","Jevil Level/Bullets/Boxes/Diamond 2"}, 0.1)
						end
						Datos.Animated = true
					end
				elseif Datos.Altura then
					if Datos.Y <= Datos.Altura then
						if Datos.Type == "Spades" then
							local inirot = math.random(360)
							for i=1,12 do
								table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Spade", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = inirot, Vel = 4})
								inirot = inirot%360 + 30
							end
						elseif Datos.Type == "Hearts" then
							table.insert(Hearts, {Bullets = {CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0), CreateProjectileAbs("Jevil Level/Bullets/Heart", 0, 0)}, X = Datos.X, Y = Datos.Y, Angulo = math.random(360), Vel = 4})
						elseif Datos.Type == "Clovers" then
							local angl = math.atan2(PosX - Datos.X, PosY - Datos.Y)/math.pi*180*-1+90
							while angl >= 360 do
								angl = angl - 360
							end
							while angl < 0 do
								angl = angl + 360
							end
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl - 20, Vel = 4})
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl, Vel = 4})
							table.insert(Spades, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover 1", 0, 0), X = Datos.X, Y = Datos.Y, Rotation = angl + 20, Vel = 4})
						elseif Datos.Type == "Diamonds" then
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 5})
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 4.5})
							table.insert(Diamonds1, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Diamond 1", 0, 0), X = Datos.X, Y = Datos.Y, Vel = 4})
						end
						Datos.Timer = 0
						Datos.Circle = CreateSprite("Jevil Level/Bullets/Explotion","BelowPlayer")
						Datos.Circle.Scale(0, 0)
						Datos.Circle.MoveTo(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
						Datos.Sprite.Remove()
						Datos.Sprite = nil
					elseif Datos.Y <= Datos.Altura + 144 and not Datos.Animated then
						if Datos.Type == "Spades" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Spade 1","Jevil Level/Bullets/Boxes/Spade 2"}, 0.1)
						elseif Datos.Type == "Hearts" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Heart 1","Jevil Level/Bullets/Boxes/Heart 2"}, 0.1)
						elseif Datos.Type == "Clovers" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Clover 1","Jevil Level/Bullets/Boxes/Clover 2"}, 0.1)
						elseif Datos.Type == "Diamonds" then
							Datos.Sprite.SetAnimation({"Jevil Level/Bullets/Boxes/Diamond 1","Jevil Level/Bullets/Boxes/Diamond 2"}, 0.1)
						end
						Datos.Animated = true
					end
				end
			else
				Datos.Timer = Datos.Timer + 1
				Datos.Circle.Scale(math.sin(math.rad(90/30*Datos.Timer)), math.sin(math.rad(90/30*Datos.Timer)))
				Datos.Circle.alpha = math.cos(math.rad(90/30*Datos.Timer))
				Datos.Circle.MoveTo(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
				if Datos.Timer >= 30 then
					Datos.Circle.Remove()
					table.remove(BoxesJ, i - tableaux)
					tableaux = tableaux + 1
				end
			end
		end
		tableaux = 0
		for i=1,#SpadeCircles do
			local Datos = SpadeCircles[i - tableaux]
			if not Datos.Timer then
				Datos.Timer = 0
			end
			Datos.Timer = Datos.Timer + 1
			if Datos.Timer <= 30 then
				Datos.X = PosX
				Datos.Y = PosY
				for j=1,10 do
					Datos.Bullets[j].MoveToAbs(320 + (Datos.X - (200 - 100*math.sin(math.rad(90/30*Datos.Timer)))*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) - (Datos.Y - (200 - 100*math.sin(math.rad(90/30*Datos.Timer)))*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)), 240 + (Datos.Y - (200 - 100*math.sin(math.rad(90/30*Datos.Timer)))*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) + (Datos.X - (200 - 100*math.sin(math.rad(90/30*Datos.Timer)))*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)))
					Datos.Bullets[j].sprite.rotation = ScreenRotation + Datos.Rotation + 36*(j - 1)
					Datos.Bullets[j].sprite.alpha = 1/30*Datos.Timer
					Datos.Bullets[j].sprite.color = {0.5,0.5,0.5}
				end
			elseif Datos.Timer <= 60 then
				Datos.X = PosX
				Datos.Y = PosY
				for j=1,10 do
					Datos.Bullets[j].MoveToAbs(320 + (Datos.X - 100*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) - (Datos.Y - 100*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)), 240 + (Datos.Y - 100*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) + (Datos.X - 100*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)))
					Datos.Bullets[j].sprite.rotation = ScreenRotation + Datos.Rotation + 36*(j - 1)
					Datos.Bullets[j].sprite.color = {0.5,0.5,0.5}
				end
			elseif Datos.Timer > 60 then
				for j=1,#Datos.Bullets do
					if not Datos.Bullets[j].GetVar("Stop") then
						Datos.Bullets[j].sprite.rotation = ScreenRotation + Datos.Rotation + 36*(j - 1)
						if Datos.Timer > 80 + 6*(j - 1) then
							table.insert(Spades, {Bullet = Datos.Bullets[j], X = (Datos.X - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.cos(math.rad(Datos.Rotation + 36*(j - 1)))), Y = (Datos.Y - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.sin(math.rad(Datos.Rotation + 36*(j - 1)))), Rotation = Datos.Bullets[j].sprite.rotation, Vel = 4})
							Datos.Bullets[j].SetVar("Stop", true)
						elseif Datos.Timer > 60 + 6*(j - 1) then
							Datos.Bullets[j].MoveToAbs(320 + (Datos.X - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) - (Datos.Y - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)), 240 + (Datos.Y - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.sin(math.rad(Datos.Rotation + 36*(j - 1))))*math.cos(math.rad(ScreenRotation)) + (Datos.X - (100 + 30*math.sin(math.rad(180/30*(Datos.Timer - (60 + 6*(j - 1))))))*math.cos(math.rad(Datos.Rotation + 36*(j - 1))))*math.sin(math.rad(ScreenRotation)))
							Datos.Bullets[j].sprite.color = {1,1,1}
						end
					end
				end
				if Datos.Timer > 140 then
					table.remove(SpadeCircles, i - tableaux)
					tableaux = tableaux + 1
				end
			end
		end
		tableaux = 0
		for i=1,#Clovers do
			local Datos = Clovers[i - tableaux]
			if not Datos.Direction then
				Datos.Direction = math.random(4)
			end
			if not Datos.Timer then
				Datos.Timer = 0
			end
			Datos.Timer = Datos.Timer + 1
			Datos.Rotation = math.atan2(PosX - Datos.X, PosY - Datos.Y)/math.pi*180*-1+90
			while Datos.Rotation >= 360 do
				Datos.Rotation = Datos.Rotation - 360
			end
			while Datos.Rotation < 0 do
				Datos.Rotation = Datos.Rotation + 360
			end
			if Datos.Timer <= 30 then
				if Datos.Direction == 1 then
					Datos.Y = 260 - 40/30*Datos.Timer
				elseif Datos.Direction == 2 then
					Datos.X = 340 - 40/30*Datos.Timer
				elseif Datos.Direction == 3 then
					Datos.Y = -260 + 40/30*Datos.Timer
				else
					Datos.X = -340 + 40/30*Datos.Timer
				end
				Datos.Bullet.sprite.alpha = 1/30*Datos.Timer
			elseif Datos.Timer > 47 and Datos.Timer <= 56 and Datos.Timer%4 == 0 then
				table.insert(Balls, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover Ball", 0, 0, "BelowBullet"), X = Datos.X, Y = Datos.Y, Rotation = Datos.Rotation - 20, Vel = 3})
				table.insert(Balls, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover Ball", 0, 0, "BelowBullet"), X = Datos.X, Y = Datos.Y, Rotation = Datos.Rotation, Vel = 3})
				table.insert(Balls, {Bullet = CreateProjectileAbs("Jevil Level/Bullets/Clover Ball", 0, 0, "BelowBullet"), X = Datos.X, Y = Datos.Y, Rotation = Datos.Rotation + 20, Vel = 3})
			elseif Datos.Timer > 60 and Datos.Timer <= 90 then
				if Datos.Direction == 1 then
					Datos.Y = 220 + 40/30*(Datos.Timer - 60)
				elseif Datos.Direction == 2 then
					Datos.X = 300 + 40/30*(Datos.Timer - 60)
				elseif Datos.Direction == 3 then
					Datos.Y = -220 - 40/30*(Datos.Timer - 60)
				else
					Datos.X = -300 - 40/30*(Datos.Timer - 60)
				end
				Datos.Bullet.sprite.alpha = 1 - 1/30*(Datos.Timer - 60)
			end
			Datos.Bullet.sprite.rotation = ScreenRotation + Datos.Rotation
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Timer >= 90 then
				Datos.Bullet.Remove()
				table.remove(Clovers, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Balls do
			local Datos = Balls[i - tableaux]
			Datos.Bullet.sprite.rotation = ScreenRotation
			Datos.X = Datos.X + Datos.Vel*math.cos(math.rad(Datos.Rotation))
			Datos.Y = Datos.Y + Datos.Vel*math.sin(math.rad(Datos.Rotation))
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.X > 560 or Datos.X < -560 or Datos.Y > 500 or Datos.Y < -500 then
				Datos.Bullet.Remove()
				table.remove(Balls, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Hearts do
			local Datos = Hearts[i - tableaux]
			if not Datos.Distancia then
				Datos.Distancia = 0
			end
			if not Datos.Aux then
				Datos.Aux = {X = Datos.X, Y = Datos.Y}
			end
			if Datos.Distancia <= 40 then
				Datos.Distancia = Datos.Distancia + 2
				Datos.Rotation = math.atan2(PosX - Datos.Aux.X, PosY - Datos.Aux.Y)/math.pi*180*-1+90
				while Datos.Rotation >= 360 do
					Datos.Rotation = Datos.Rotation - 360
				end
				while Datos.Rotation < 0 do
					Datos.Rotation = Datos.Rotation + 360
				end
			else
				Datos.Angulo = Datos.Angulo + 2
				Datos.Aux.X = Datos.Aux.X + Datos.Vel*math.cos(math.rad(Datos.Rotation))
				Datos.Aux.Y = Datos.Aux.Y + Datos.Vel*math.sin(math.rad(Datos.Rotation))
			end
			for j=1,4 do
				Datos.X = Datos.Aux.X + Datos.Distancia*math.cos(math.rad(Datos.Angulo + 90*(j - 1))) 
				Datos.Y = Datos.Aux.Y + Datos.Distancia*math.sin(math.rad(Datos.Angulo + 90*(j - 1)))
				Datos.Bullets[j].sprite.rotation = ScreenRotation
				Datos.Bullets[j].MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			end
			if Datos.Aux.X > 600 or Datos.Aux.X < -600 or Datos.Aux.Y > 540 or Datos.Aux.Y < -540 then
				for j=1,4 do
					Datos.Bullets[j].Remove()
				end
				table.remove(Hearts, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Spades do
			local Datos = Spades[i - tableaux]
			Datos.Bullet.sprite.rotation = ScreenRotation + Datos.Rotation
			Datos.X = Datos.X + Datos.Vel*math.cos(math.rad(Datos.Rotation))
			Datos.Y = Datos.Y + Datos.Vel*math.sin(math.rad(Datos.Rotation))
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.X > 560 or Datos.X < -560 or Datos.Y > 500 or Datos.Y < -500 then
				Datos.Bullet.Remove()
				table.remove(Spades, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Diamonds1 do
			local Datos = Diamonds1[i - tableaux]
			if not Datos.Rotation then
				local angl = math.atan2(PosX - Datos.X, PosY - Datos.Y)/math.pi*180*-1+90
				while angl >= 360 do
					angl = angl - 360
				end
				while angl < 0 do
					angl = angl + 360
				end
				Datos.Rotation = angl
			end
			Datos.Bullet.sprite.rotation = ScreenRotation + Datos.Rotation
			Datos.X = Datos.X + Datos.Vel*math.cos(math.rad(Datos.Rotation))
			Datos.Y = Datos.Y + Datos.Vel*math.sin(math.rad(Datos.Rotation))
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.X > 560 or Datos.X < -560 or Datos.Y > 500 or Datos.Y < -500 then
				Datos.Bullet.Remove()
				table.remove(Diamonds1, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		for i=1,#Diamonds2 do
			local Datos = Diamonds2[i - tableaux]
			if not Datos.Vel then
				Datos.Vel = -2
				Datos.Bullet.sprite.Scale(2, 2)
				Datos.Bullet.sprite.alpha = 0
			end
			Datos.Bullet.sprite.rotation = ScreenRotation
			Datos.Y = Datos.Y + Datos.Vel
			Datos.Vel = Datos.Vel + 4/30
			Datos.Bullet.sprite.Scale(math.max(Datos.Bullet.sprite.xscale - 1/30, 1), math.max(Datos.Bullet.sprite.yscale - 1/30, 1))
			Datos.Bullet.sprite.alpha = Datos.Bullet.sprite.alpha + 1/30
			Datos.Bullet.MoveToAbs(320 + Datos.X*math.cos(math.rad(ScreenRotation)) - Datos.Y*math.sin(math.rad(ScreenRotation)), 240 + Datos.Y*math.cos(math.rad(ScreenRotation)) + Datos.X*math.sin(math.rad(ScreenRotation)))
			if Datos.Y > 500 then
				Datos.Bullet.Remove()
				table.remove(Diamonds2, i - tableaux)
				tableaux = tableaux + 1
			end
		end
		tableaux = 0
		if timer > 0 and NewAudio.GetPlayTime("Song") > 183.14 then
			if Input.Up > 0 and Input.Down == 0 then
				PosY = math.min(PosY + 8, 232)
			elseif Input.Down > 0 and Input.Up == 0 then
				PosY = math.max(PosY - 8, -232)
			end
			if Input.Right > 0 and Input.Left == 0 then
				PosX = math.min(PosX + 8, 312)
			elseif Input.Left > 0 and Input.Right == 0 then
				PosX = math.max(PosX - 8, -312)
			end
		else
			if Input.Up > 0 and Input.Down == 0 then
				PosY = math.min(PosY + 4, 232)
			elseif Input.Down > 0 and Input.Up == 0 then
				PosY = math.max(PosY - 4, -232)
			end
			if Input.Right > 0 and Input.Left == 0 then
				PosX = math.min(PosX + 4, 312)
			elseif Input.Left > 0 and Input.Right == 0 then
				PosX = math.max(PosX - 4, -312)
			end
		end
		Player.sprite.rotation = ScreenRotation
		Player.MoveToAbs(320 + PosX*math.cos(math.rad(ScreenRotation)) - PosY*math.sin(math.rad(ScreenRotation)), 240 + PosY*math.cos(math.rad(ScreenRotation)) + PosX*math.sin(math.rad(ScreenRotation)), true)
		if Numbers and Numbers[1].isactive and Numbers[2].isactive then
			HPUpdate()
		end
		BlackD.SendToTop()
		if Input.GetKey("P") == 1 then
			Pause = 0
			if not NewAudio.isStopped("Song") then
				Detenido = true
				NewAudio.Pause("Song")
			end
		end
	else
		if Pause == 0 then
			if not Text and not Option1 and not Option2 then
				Text = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Pausa","Top")
				Option1 = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Continuar","Top")
				Option2 = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Quitar","Top")
				Text.MoveTo(320, 260)
				Option1.MoveTo(170, 200)
				Option2.MoveTo(470, 200)
			end
			BlackD.alpha = BlackD.alpha + 0.02
			Text.alpha = BlackD.alpha*2
			Option1.alpha = BlackD.alpha*2
			Option2.alpha = BlackD.alpha*2
			if BlackD.alpha >= 0.5 then
				Pause = 1
				Audio.PlaySound("pip")
			end
		elseif Pause == 1 then
			Option1.color = {1,1,0}
			Option2.color = {1,1,1}
			if Input.Right == 1 then
				Pause = 2
				Audio.PlaySound("pip")
			elseif Input.Confirm == 1 then
				Audio.PlaySound("confirm")
				Option1.color = {1,1,1}
				Option2.color = {1,1,1}
				Pause = 3
			end
		elseif Pause == 2 then
			Option1.color = {1,1,1}
			Option2.color = {1,1,0}
			if Input.Left == 1 then
				Pause = 1
				Audio.PlaySound("pip")
			elseif Input.Confirm == 1 then
				Audio.PlaySound("confirm")
				Option1.color = {1,1,1}
				Option2.color = {1,1,1}
				Pause = 4
			end
		elseif Pause == 3 then
			BlackD.alpha = BlackD.alpha - 0.02
			Text.alpha = BlackD.alpha*2
			Option1.alpha = BlackD.alpha*2
			Option2.alpha = BlackD.alpha*2
			if BlackD.alpha <= 0 then
				Text.Remove()
				Option1.Remove()
				Option2.Remove()
				Text = nil
				Option1 = nil
				Option2 = nil
				if Detenido then
					NewAudio.Unpause("Song")
					Detenido = nil
				end
				Pause = nil
			end
		elseif Pause == 4 then
			BlackD.alpha = BlackD.alpha + 0.02
			Text.alpha = Text.alpha - 0.04
			Option1.alpha = Text.alpha
			Option2.alpha = Text.alpha
			if BlackD.alpha >= 1 then
				if not wait2 then
					wait2 = 0
				end
				wait2 = wait2 + 1
				if wait2 == 60 then
					Text.Remove()
					Option1.Remove()
					Option2.Remove()
					Text = nil
					Option1 = nil
					Option2 = nil
					Pause = 5
					EndAll = true
				end
			end
		end
	end
	if EndAll then
		RemoveAll()
		if Black then
			Black.Remove()
		end
		BlackD.Remove()
		if Index1 and Index2 then
			Index1.Remove()
			Index2.Remove()
			Index1 = nil
			Index2 = nil
		end
		if BG1 and BG2 then
			BG1.Remove()
			BG2.Remove()
			BG1 = nil
			BG2 = nil
		end
		if TituloSong then
			TituloSong.Remove()
		end
		if VersionLevel then
			VersionLevel.Remove()
		end
		if Advice then
			Advice.Remove()
		end
		for i=1,#Jevil do
			Jevil[i - tableaux].Sprite.Remove()
			table.remove(Jevil, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		for i=1,#BoxesJ do
			if BoxesJ[i - tableaux].Sprite then
				BoxesJ[i - tableaux].Sprite.Remove()
			end
			if BoxesJ[i - tableaux].Circle then
				BoxesJ[i - tableaux].Circle.Remove()
			end
			table.remove(BoxesJ, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		NewAudio.Stop("Song")
		NewAudio.DestroyChannel("Song")
		Start = nil
		Encounter["nextwaves"] = {"MenuJ"}
		State("ACTIONSELECT")
		State("DEFENDING")
	end
end

function OnHit(bullet)
	if bullet.sprite.alpha > 0.9 and not bullet.GetVar("No Damage")and not Pause then
		if Player.hp > 1 then
			Player.Hurt(1)
		elseif not Player.isHurting then
			Player.Hurt(0)
			RemoveAll()
			if Index1 and Index2 then
				Index1.Remove()
				Index2.Remove()
				Index1 = nil
				Index2 = nil
			end
			if BG1 and BG2 then
				BG1.Remove()
				BG2.Remove()
				BG1 = nil
				BG2 = nil
			end
			for i=1,#Jevil do
				Jevil[i - tableaux].Sprite.Remove()
				table.remove(Jevil, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			for i=1,#BoxesJ do
				if BoxesJ[i - tableaux].Sprite then
					BoxesJ[i - tableaux].Sprite.Remove()
				end
				if BoxesJ[i - tableaux].Circle then
					BoxesJ[i - tableaux].Circle.Remove()
				end
				table.remove(BoxesJ, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			Encounter["nextwaves"] = {"Undertale Game Over J"}
			State("ACTIONSELECT")
			State("DEFENDING")
		end
	end
end