require "Dialogs"

timer = 0
phases = {0, 0}
AuxX = 320
AuxY = -5
BFX = 80
BAX = 80
BIX = 560
BMX = 560
BFY = 300
BAY = 240
BIY = 300
BMY = 240
PapsX = 310
PapsY = 220
SX = 350
SY = 160.5

require "Rotatory Arena"
PosY = 10.5
PosX = 0.5
FakeArena.ResizeImmediate(565, 135)
FakeArena.MoveTo(AuxX, AuxY, true)
Encounter.Call("AttackAnim", 2)
Encounter.Call("PapsMoveTo", {PapsX, PapsY})
Encounter.Call("StatusMoveTo", {SX, SY})
Encounter.Call("RotateButton", {"Fight", 0})
Encounter.Call("RotateButton", {"Act", 0})
Encounter.Call("RotateButton", {"Item", 0})
Encounter.Call("RotateButton", {"Mercy", 0})
Encounter.Call("ButtonMoveTo", {"Fight", BFX, BFY})
Encounter.Call("ButtonMoveTo", {"Act", BAX, BAY})
Encounter.Call("ButtonMoveTo", {"Item", BIX, BIY})
Encounter.Call("ButtonMoveTo", {"Mercy", BMX, BMY})
FakeArena.Update()

state = 1
maxjump = 40
jump = 0
newpX = PosX
newpY = PosY
Encounter["progress"] = 3

SetPPCollision(true)

GBPaps = {}
Huesos1 = {}
Huesos2 = {}
Huesos3 = {}
Huesos4 = {}
Huesos5 = {}
Huesos6 = {}
SpecialBones = {}

function RecolorSoul()
	if state ~= 1 and state ~= 2 then
		Player.sprite.color = {1.0,0.0,0.0}
		Player.sprite.rotation = 0
	elseif state == 1 or state == 2 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 0
	end
end

RecolorSoul()

function Update()
	timer = timer + 1
	if timer == 25 then
		state = 0
		RecolorSoul()
		Audio.PlaySound("ding")
		Encounter.Call("ContinueMusic")
		NewAudio.SetPlayTime("One", 0)
	elseif timer == 26 then
		NewAudio.SetPlayTime("One", 0)
	elseif timer > 26 then
		if NewAudio.GetPlayTime("One") > 0 and phases[1] == 0 then
			if NewAudio.GetPlayTime("One") <= 0.55 then
				FakeArena.Resize(565 - 425*math.sin(math.rad(90/0.55*NewAudio.GetPlayTime("One"))), 135)
			elseif NewAudio.GetPlayTime("One") <= 0.73 then
				FakeArena.Resize(140 + 20 - 20*math.cos(math.rad(90/0.18*(NewAudio.GetPlayTime("One") - 0.55))), 135)
			elseif NewAudio.GetPlayTime("One") <= 1.25 then
				FakeArena.Resize(160, 135 - 109*math.sin(math.rad(90/0.52*(NewAudio.GetPlayTime("One") - 0.73))), true)
				AuxY = -5 + 110*math.sin(math.rad(90/0.52*(NewAudio.GetPlayTime("One") - 0.73)))
			else
				FakeArena.Resize(160, 26, true)
				AuxY = 105
				phases[1] = 1
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 1.37 and phases[1] == 1 then
			if NewAudio.GetPlayTime("One") <= 1.77 then
				AuxY = 82.5 + 22.5*math.cos(math.rad(180/0.4*(NewAudio.GetPlayTime("One") - 1.37)))
			else
				AuxY = 60
				phases[1] = 2
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 2.5 and phases[1] == 2 then
			if NewAudio.GetPlayTime("One") <= 5.48 then
				AuxX = 320 - 215/2.98*(NewAudio.GetPlayTime("One") - 2.5)
				FakeArena.rotation = -360/2.98*(NewAudio.GetPlayTime("One") - 2.5)
			else
				AuxX = 105
				FakeArena.rotation = 0
				phases[1] = 3
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 5.95 and phases[1] == 3 then
			if NewAudio.GetPlayTime("One") <= 6.45 then
				FakeArena.rotation = -90/0.5*(NewAudio.GetPlayTime("One") - 5.95)
				AuxX = 165 - 60*math.cos(math.rad(FakeArena.rotation))
				AuxY = 60 - 60*math.sin(math.rad(FakeArena.rotation))
			else
				FakeArena.rotation = 90
				AuxX = 165
				AuxY = 120
				phases[1] = 4
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 6.45 and phases[1] == 4 then
			if NewAudio.GetPlayTime("One") <= 7.26 then
				AuxY = 120 - 65*math.sin(math.rad(90/0.81*(NewAudio.GetPlayTime("One") - 6.45)))
				FakeArena.Resize(160 - 26/0.81*(NewAudio.GetPlayTime("One") - 6.45), 26)
			else
				AuxY = 0
				FakeArena.ResizeImmediate(26, 134)
				FakeArena.rotation = 0
				FakeArena.MoveTo(AuxX, AuxY, true)
				phases[1] = 5
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 13.45 and phases[1] == 5 then
			if NewAudio.GetPlayTime("One") <= 15.73 then
				AuxX = 165 + 403/2.28*(NewAudio.GetPlayTime("One") - 13.45)
			else
				AuxX = 568
				phases[1] = 6
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 15.73 and phases[1] == 6 then
			if NewAudio.GetPlayTime("One") <= 16.36 then
				if NewAudio.GetPlayTime("One") > 16 and state == 0 then
					state = 1
					newpX = PosX
					newpY = PosY
					RecolorSoul()
					Audio.PlaySound("ding")
				end
				FakeArena.Resize(26 + 494/0.63*(NewAudio.GetPlayTime("One") - 15.73), 134)
				AuxX = 568 - 248/0.63*(NewAudio.GetPlayTime("One") - 15.73)
			else
				if NewAudio.GetPlayTime("One") > 16 and state == 0 then
					state = 1
					newpX = PosX
					newpY = PosY
					RecolorSoul()
					Audio.PlaySound("ding")
				end
				FakeArena.Resize(520, 134)
				AuxX = 320
				phases[1] = 7
				Black1 = CreateSprite("Rotatory Arena Pixel", "Top")
				Black2 = CreateSprite("Rotatory Arena Pixel", "Top")
				Black1.Scale(60, 144)
				Black2.Scale(60, 144)
				Black1.MoveTo(25, 72)
				Black2.MoveTo(640 - 25, 72)
				Black1.color = {0,0,0}
				Black2.color = {0,0,0}
				Bone = CreateProjectileAbs("Bullets/Bones/Right Bone", 0, 72)
			end
			FakeArena.MoveTo(AuxX, AuxY)
			if state ~= 0 then
				newpX = PosX
				newpY = PosY
			end
		elseif NewAudio.GetPlayTime("One") > 16.36 and phases[1] == 7 then
			if NewAudio.GetPlayTime("One") <= 20.12 then
				if NewAudio.GetPlayTime("One") > 17.74 and not Blasters then
					table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 260, Y = -60, rotation = 0}, DatosFinales = {X = 260, Y = 60, rotation = -90}}, Scale = 0.6, Delay = 30, Duration = 45})
					table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 380, Y = -60, rotation = 0}, DatosFinales = {X = 380, Y = 60, rotation = 90}}, Scale = 0.6, Delay = 30, Duration = 45})
					Audio.PlaySound("gasterintro")
					Audio.PlaySound("gasterintro2")
					Blasters = true
				end
				Bone.MoveToAbs(640/3.76*(NewAudio.GetPlayTime("One") - 16.36), 72)
				Bone.sprite.rotation = -810/3.76*(NewAudio.GetPlayTime("One") - 16.36)
			else
				Bone.Remove()
				Bone = nil
				phases[1] = 8
			end
		elseif NewAudio.GetPlayTime("One") > 20.75 and phases[1] == 8 then
			if NewAudio.GetPlayTime("One") <= 21.16 then
				FakeArena.Resize(520, 134 - 118/0.41*(NewAudio.GetPlayTime("One") - 20.75))
				AuxY = 118/0.41*(NewAudio.GetPlayTime("One") - 20.75)
			else
				FakeArena.Resize(520, 16)
				AuxY = 118
				state = 3
				Black1.Remove()
				Black2.Remove()
				Black1 = nil
				Black2 = nil
				table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 647, 131), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 6, Vel = -1.5, Mayor = 647, Menor = -6})
				for i=1,16 do
					if i == 1 or i == 4 or i == 5 or i == 7 or i == 9 or i == 12 or i == 13 or i == 15 then
						table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", -7 - 50*(i - 1), 131), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Color = {33/255, 197/255, 1}, Tipo = "Blue", Longitud = 6, Vel = 5, Mayor = 646, Menor = -900})
					else
						table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", -7 - 50*(i - 1), 131), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Color = {1, 150/255, 0}, Tipo = "Orange", Longitud = 6, Vel = 5, Mayor = 646, Menor = -900})
					end
				end
				phases[1] = 9
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 21.37 and phases[1] == 9 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 1}, DatosFinales = {X = 418, Y = 44, rotation = 180}}, Delay = 30, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 10
		elseif NewAudio.GetPlayTime("One") > 21.87 and phases[1] == 10 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = -38, Y = 530, rotation = 359}, DatosFinales = {X = 266, Y = 44, rotation = 180}}, Delay = 0, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 11
		elseif NewAudio.GetPlayTime("One") > 23.56 and phases[1] == 11 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 1}, DatosFinales = {X = 360, Y = 53, rotation = 240}}, Delay = 60, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 12
		elseif NewAudio.GetPlayTime("One") > 23.81 and phases[1] == 12 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = -38, Y = 530, rotation = 359}, DatosFinales = {X = 70, Y = 44, rotation = 180}}, Delay = 45, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 13
		elseif NewAudio.GetPlayTime("One") > 26.16 and phases[1] == 13 then
			table.insert(Huesos3, {Body = CreateProjectileAbs("Bullets/Bones/Body", 647, 63), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 126, Vel = -8, Mayor = 647, Menor = -6})
			phases[1] = 14
		elseif NewAudio.GetPlayTime("One") > 26.58 and phases[1] == 14 then
			if NewAudio.GetPlayTime("One") <= 26.88 then
				state = 2
				FakeArena.Resize(520, 16 + 112/0.3*(NewAudio.GetPlayTime("One") - 26.58))
				AuxY = 118 - 112/0.3*(NewAudio.GetPlayTime("One") - 26.58)
			else
				state = 2
				FakeArena.Resize(520, 128)
				AuxY = 6
				phases[1] = 15
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 26.99 and phases[1] == 15 then
			table.insert(Huesos4, {Body = CreateProjectileAbs("Bullets/Bones/Body4", 81, 139), Head = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), PosY = 139, PosX = 81, Longitud = 0, Direction = 64})
			phases[1] = 16
		elseif NewAudio.GetPlayTime("One") > 27.32 and phases[1] == 16 then
			table.insert(Huesos4, {Body = CreateProjectileAbs("Bullets/Bones/Body4", 121, 139), Head = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), PosY = 139, PosX = 121, Longitud = 0, Direction = 64})
			phases[1] = 17
		elseif NewAudio.GetPlayTime("One") > 27.65 and phases[1] == 17 then
			table.insert(Huesos4, {Body = CreateProjectileAbs("Bullets/Bones/Body4", 161, 11), Head = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head4", 0, 0), PosY = 11, PosX = 161, Longitud = 0, Direction = -64})
			phases[1] = 18
		elseif NewAudio.GetPlayTime("One") > 27.98 and phases[1] == 18 then
			Audio.PlaySound("ding")
			for i=1,#Huesos4 do
				Huesos4[i].Timer = 21
				Huesos4[i].Y = Huesos4[i].PosY - Huesos4[i].Direction
				Huesos4[i].Longitud = 118
			end
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 0}, DatosFinales = {X = 500, Y = 58, rotation = -90}}, Delay = 20, Duration = 40})
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = -38, Y = 530, rotation = 0}, DatosFinales = {X = 262, Y = 130, rotation = 0}}, Delay = 20, Duration = 40})
			Audio.PlaySound("gasterintro")
			phases[1] = 19
		elseif NewAudio.GetPlayTime("One") > 30.3 and phases[1] == 19 then
			state = 4
			jump = 47
			phases[1] = 20
		elseif NewAudio.GetPlayTime("One") > 30.5 and phases[1] == 20 then
			local borde = CreateSprite("Pixel","Top")
			borde.Scale(220, 128)
			borde.MoveTo(320, 75)
			borde.Mask("stencil")
			local misil = CreateProjectileAbs("Bullets/Bones/BonesDown", 319.5, -194)
			misil.sprite.SetParent(borde)
			table.insert(Huesos5, {Body = misil, Bound = borde, X = 319.5, Y = -194})
			phases[1] = 21
		elseif NewAudio.GetPlayTime("One") > 32.51 and phases[1] == 21 then
			if state == 4 then
				state = 5
				jump = -150
			end
			if NewAudio.GetPlayTime("One") <= 32.72 then
				BFX = 80 - 140/0.21*(NewAudio.GetPlayTime("One") - 32.51)
				FakeArena.Resize(210 + 150*math.sin(math.rad(90/0.21*(NewAudio.GetPlayTime("One") - 32.51))), 128 - 82*math.sin(math.rad(90/0.21*(NewAudio.GetPlayTime("One") - 32.51))), true)
				AuxY = 6 + 82*math.sin(math.rad(90/0.21*(NewAudio.GetPlayTime("One") - 32.51)))
			else
				BFX = -200
				FakeArena.Resize(360, 46, true)
				AuxY = 88
				phases[1] = 22
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 32.73 and phases[1] == 22 then
			if state == 5 then
				state = 6
				jump = -150
			end
			if NewAudio.GetPlayTime("One") <= 32.93 then
				BIX = 560 + 140/0.2*(NewAudio.GetPlayTime("One") - 32.73)
				FakeArena.Resize(360 - 260*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 32.73))), 46, true)
				AuxX = 320 + 130*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 32.73)))
			else
				BIX = 840
				FakeArena.Resize(100, 46, true)
				AuxX = 450
				phases[1] = 23
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 32.94 and phases[1] == 23 then
			if state == 6 then
				Player.sprite.rotation = -90
				state = 7
				jump = -150
			end
			if NewAudio.GetPlayTime("One") <= 33.14 then
				BAX = 80 - 140/0.2*(NewAudio.GetPlayTime("One") - 32.94)
				FakeArena.Resize(100, 46 + 82*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 32.94))), true)
				AuxX = 450 - 120*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 32.94)))
				AuxY = 88 - 82*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 32.94)))
			else
				BAX = -200
				FakeArena.Resize(100, 128, true)
				AuxX = 330
				AuxY = 6
				phases[1] = 24
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 33.15 and phases[1] == 24 then
			jump = -40
			if NewAudio.GetPlayTime("One") <= 33.35 then
				BMX = 560 + 140/0.2*(NewAudio.GetPlayTime("One") - 33.15)
				FakeArena.Resize(100 + 540*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 33.15))), 128, true)
				AuxX = 330 + 5*math.sin(math.rad(90/0.2*(NewAudio.GetPlayTime("One") - 33.15)))
			else
				BMX = 840
				FakeArena.Resize(640, 128, true)
				AuxX = 335
				speed = 60
				phases[1] = 25
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 34.91 and phases[1] == 25 then
			table.insert(SpecialBones, {Bullet = CreateProjectileAbs("Bullets/Bones/Right Bone v2", 700, 100), Vel = -20, Rotation = -135, Delete = -150})
			table.insert(SpecialBones, {Bullet = CreateProjectileAbs("Bullets/Bones/Right Bone v2", 840, 50), Vel = -16, Rotation = -135, Delete = -150})
			table.insert(SpecialBones, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneWay", 1174, 75), Vel = -12, Generar = 3, Rotation = 0, Delete = -270})
			phases[1] = 26
		elseif NewAudio.GetPlayTime("One") > 39.7 and phases[1] == 26 then
			if Limite ~= 20 then
				Limite = 20
			end
			if not FakeLenght then
				FakeLenght = {CreateSprite("Rotatory Arena Pixel", "BelowPlayer"), CreateSprite("Rotatory Arena Pixel", "BelowPlayer")}
				FakeLenght2 = {CreateSprite("Rotatory Arena Pixel", "BelowPlayer"), CreateSprite("Rotatory Arena Pixel", "BelowPlayer")}
				FakeLenght[1].Scale(256, 114)
				FakeLenght2[1].Scale(256, 104)
				FakeLenght[2].Scale(138, 114)
				FakeLenght2[2].Scale(128, 104)
				FakeLenght2[1].color = {0,0,0}
				FakeLenght2[2].color = {0,0,0}
				FakeLenght[2].alpha = 0
				FakeLenght[1].MoveTo(128, FakeArena1.y)
				FakeLenght2[1].MoveTo(128, FakeArena1.y)
				FakeLenght[2].MoveTo(FakeArena1.x, 75)
				FakeLenght2[2].MoveTo(FakeArena1.x, 75)
			end
			if NewAudio.GetPlayTime("One") <= 40.12 then
				FakeArena.Resize(640 - 512/0.42*(NewAudio.GetPlayTime("One") - 39.7), 104)
			else
				FakeArena.Resize(128, 104)
				phases[1] = 27
			end
		elseif NewAudio.GetPlayTime("One") > 40.12 and phases[1] == 27 then
			if state == 8 then
				state = 9
				jump = 30
				Player.sprite.rotation = 180
				FakeLenght[2].alpha = 1
				Audio.PlaySound("pierce")
			end
			if NewAudio.GetPlayTime("One") <= 40.36 then
				SY = 160.5 + 376/0.24*(NewAudio.GetPlayTime("One") - 40.12)
				FakeLenght[2].Scale(138, 114 + 376/0.24*(NewAudio.GetPlayTime("One") - 40.12))
				FakeLenght2[2].Scale(128, 104 + 376/0.24*(NewAudio.GetPlayTime("One") - 40.12))
			else
				SY = 536.5
				FakeLenght[2].Scale(138, 490)
				FakeLenght2[2].Scale(128, 480)
				speed2 = 0
				phases[1] = 28
			end
			FakeLenght[2].MoveTo(FakeArena1.x, 18 + FakeLenght[2].yscale/2)
			FakeLenght2[2].MoveTo(FakeArena1.x, 23 + FakeLenght2[2].yscale/2)
		elseif phases[1] == 28 and jump <= 0 then
			speed2 = speed2 - 2
			FakeLenght[1].MoveTo(128, FakeLenght[1].y + (speed2/10))
			FakeLenght2[1].MoveTo(128, FakeLenght2[1].y + (speed2/10))
			FakeLenght[2].MoveTo(FakeArena1.x, math.max(FakeLenght[2].y + (speed2/10), 240))
			FakeLenght2[2].MoveTo(FakeArena1.x, math.max(FakeLenght2[2].y + (speed2/10), 240))
			if FakeLenght[1].y <= -60 then
				speed2 = nil
				phases[1] = 29
			end
		elseif phases[1] == 29 and Arena.width > 104 then
			FakeArena.ResizeImmediate(128 - 24/120, 104)
			FakeLenght[2].xscale = 138 - 24/120
			FakeLenght2[2].xscale = 128 - 24/120
			if Arena.width <= 104 then
				FakeArena.Resize(104, 104)
				phases[1] = 30
			end
		elseif NewAudio.GetPlayTime("One") > 43.23 and phases[1] == 30 then
			if Black.alpha >= 1 then
				newpX = 0
				newpY = 0
				PosX = newpX
				PosY = newpY
				Audio.PlaySound("ding")
				NewAudio.SetVolume("One", 1)
				Black.alpha = 0
			end
			if NewAudio.GetPlayTime("One") <= 43.64 then
				FakeArena.Resize(16 + 584*math.cos(math.rad(90/0.41*(NewAudio.GetPlayTime("One") - 43.23))), 16 + 424*math.cos(math.rad(90/0.41*(NewAudio.GetPlayTime("One") - 43.23))))
				AuxY = 227 - 212*math.cos(math.rad(90/0.41*(NewAudio.GetPlayTime("One") - 43.23)))
			else
				FakeArena.Resize(16, 16)
				AuxY = 227
				phases[1] = 31
			end
		elseif NewAudio.GetPlayTime("One") > 46.3 and phases[1] == 31 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = -38, Y = 530, rotation = 0}, DatosFinales = {X = 180, Y = 287.5, rotation = 45}, VelAppearing = 24}, Delay = 6, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 32
		elseif NewAudio.GetPlayTime("One") > 46.9 and phases[1] == 32 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 0}, DatosFinales = {X = 476, Y = 287.5, rotation = 0}, VelAppearing = 24}, Delay = 6, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[1] = 33
		end
		if NewAudio.GetPlayTime("One") > 1.77 and phases[2] == 0 then
			table.insert(Huesos1, {Body = CreateProjectileAbs("Bullets/Bones/BoneWall", 165, -72), Aparicion = 60*(2.5 - 1.77), Desaparecer = 14})
			phases[2] = 1
		elseif NewAudio.GetPlayTime("One") > 7.62 and phases[2] == 1 then
			table.insert(Huesos1, {Body = CreateProjectileAbs("Bullets/Bones/BoneWall", 350, -72), Aparicion = 60*(7.75 - 7.62), Desaparecer = 15})
			phases[2] = 2
		elseif NewAudio.GetPlayTime("One") > 8.04 and phases[2] == 2 then
			table.insert(Huesos1, {Body = CreateProjectileAbs("Bullets/Bones/BoneWall", 535, -72), Aparicion = 60*(8.26 - 8.04), Desaparecer = 15.7})
			phases[2] = 3
		elseif NewAudio.GetPlayTime("One") > 8.34 and phases[2] == 3 then
			if not BubbleS then
				BubbleS = CreateSprite("UI/SpeechBubbles/rightwide", "Top")
			end
			if NewAudio.GetPlayTime("One") <= 8.64 then
				BubbleS.MoveTo(490.5, 600 - 205/0.3*(NewAudio.GetPlayTime("One") - 8.34))
			else
				phases[2] = 4
			end
		elseif NewAudio.GetPlayTime("One") > 8.64 and phases[2] == 4 then
			if BubbleS then
				BubbleS.Remove()
				BubbleS = nil
			end
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus][waittall:0.5]Cómo puedo\nlamentarlo?[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus]Как я могу\nсожалеть?[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:mad papyrus]How can I be\nsorry?[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			phases[2] = 5
		elseif NewAudio.GetPlayTime("One") > 10.21 and phases[2] == 5 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus][waittall:0.5]Después de todo\nlo que hiciste...[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus]После всего,\nчто ты сделал...[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:mad papyrus]After all you\ndid...[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			phases[2] = 6
		elseif NewAudio.GetPlayTime("One") > 11.9 and phases[2] == 6 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus]Te mereces esto.[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				Bubble("[noskip][font:papyrus][voice:mad papyrus]Ты этого\nзаслуживаешь.[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			else
				Bubble("[noskip][font:papyrus][voice:mad papyrus]You deserve this.[w:20] ", "rightwide", 490.5, 395, 40, 90, 1)
			end
			phases[2] = 7
		elseif NewAudio.GetPlayTime("One") > 12.95 and phases[2] == 7 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 0}, DatosFinales = {X = 535, Y = -4, rotation = -90}}, Delay = 0, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[2] = 8
		elseif NewAudio.GetPlayTime("One") > 13.45 and phases[2] == 8 then
			Bubble("", "", "", "", "", "", 1)
			Encounter.Call("AttackAnim", 1)
			phases[2] = 9
		elseif NewAudio.GetPlayTime("One") > 13.5 and phases[2] == 9 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 0}, DatosFinales = {X = 250, Y = 210, rotation = 0}}, Delay = 0, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[2] = 10
		elseif NewAudio.GetPlayTime("One") > 14.1 and phases[2] == 10 then
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 678, Y = 530, rotation = 0}, DatosFinales = {X = 350, Y = 210, rotation = 0}}, Delay = 0, Duration = 30})
			Audio.PlaySound("gasterintro")
			phases[2] = 11
		elseif NewAudio.GetPlayTime("One") > 16.36 and phases[2] == 11 then
			for i=1,4 do
				table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 55 - 14*(i - 1), 20), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 20, Vel = 5, Mayor = FakeArena.x + Arena.width/2 + 2.5, Menor = 0})
			end
			phases[2] = 12
		elseif NewAudio.GetPlayTime("One") > 17.26 and phases[2] == 12 then
			for i=1,4 do
				table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 55 - 14*(i - 1), 20), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 20, Vel = 5, Mayor = FakeArena.x + Arena.width/2 + 2.5, Menor = 0})
			end
			phases[2] = 13
		elseif NewAudio.GetPlayTime("One") > 18.74 and phases[2] == 13 then
			for i=1,4 do
				table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 55 - 14*(i - 1), 20), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 20, Vel = 5, Mayor = FakeArena.x + Arena.width/2 + 2.5, Menor = 0})
			end
			phases[2] = 14
		elseif NewAudio.GetPlayTime("One") > 26.49 and phases[2] == 14 then
			Warn = CreateSprite("Rotatory Arena Pixel", "BelowPlayer")
			Warn.Scale(42, 128)
			Warn.MoveTo(81, 75)
			phases[2] = 15
		elseif NewAudio.GetPlayTime("One") > 26.82 and phases[2] == 15 then
			Warn.Scale(82, 128)
			Warn.MoveTo(101, 75)
			phases[2] = 16
		elseif NewAudio.GetPlayTime("One") > 27.15 and phases[2] == 16 then
			Warn.Scale(122, 128)
			Warn.MoveTo(121, 75)
			phases[2] = 17
		elseif NewAudio.GetPlayTime("One") > 27.32 and phases[2] == 17 then
			Warn.Scale(82, 128)
			Warn.MoveTo(141, 75)
			phases[2] = 18
		elseif NewAudio.GetPlayTime("One") > 27.65 and phases[2] == 18 then
			Warn.Scale(42, 128)
			Warn.MoveTo(161, 75)
			phases[2] = 19
		elseif NewAudio.GetPlayTime("One") > 27.98 and phases[2] == 19 then
			Warn.Remove()
			Warn = nil
			phases[2] = 20
		elseif NewAudio.GetPlayTime("One") > 28.1 and phases[2] == 20 then
			if NewAudio.GetPlayTime("One") <= 29.1 then
				FakeArena.Resize(442.5 + 77.5*math.cos(math.rad(180*(NewAudio.GetPlayTime("One") - 28.1))), 128, true)
				AuxX = 358.75 - 38.75*math.cos(math.rad(180*(NewAudio.GetPlayTime("One") - 28.1)))
			else
				FakeArena.Resize(365, 128, true)
				AuxX = 397.5
				phases[2] = 21
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif NewAudio.GetPlayTime("One") > 29.7 and phases[2] == 21 then
			if NewAudio.GetPlayTime("One") <= 30.2 then
				FakeArena.Resize(287.5 + 77.5*math.cos(math.rad(360*(NewAudio.GetPlayTime("One") - 29.7))), 128, true)
				AuxX = 358.75 + 38.75*math.cos(math.rad(360*(NewAudio.GetPlayTime("One") - 29.7)))
			else
				FakeArena.Resize(210, 128, true)
				AuxX = 320
				phases[2] = 22
			end
			FakeArena.MoveTo(AuxX, AuxY, true)
		elseif phases[2] == 23 and AuxX > 320 then
			if jump <= 0 then
				AuxX = math.max(AuxX + (jump/10), 320)
				if AuxX <= 320 then
					phases[2] = 24
				end
			end
		elseif NewAudio.GetPlayTime("One") > 34.18 and phases[2] == 24 then
			if NewAudio.GetPlayTime("One") <= 36.18 then
				FakeArena.Resize(640, 128 - 24/2*(NewAudio.GetPlayTime("One") - 34.18))
				AuxY = 6 + 12/2*(NewAudio.GetPlayTime("One") - 34.18)
			else
				FakeArena.Resize(640, 104)
				AuxY = 18
				phases[2] = 25
			end
			FakeArena.MoveTo(AuxX, AuxY)
		elseif NewAudio.GetPlayTime("One") > 40.95 and phases[2] == 25 then
			if not FakeGB then
				FakeGB = CreateSprite("Bullets/GB Papyrus/0", "Top")
				Audio.PlaySound("gasterintro")
			end
			if NewAudio.GetPlayTime("One") <= 41.45 then
				FakeGB.MoveTo(320, 530 - 240*math.sin(math.rad(90/0.5*(NewAudio.GetPlayTime("One") - 40.95))))
			else
				FakeGB.MoveTo(320, 290)
				phases[2] = 26
			end
		elseif NewAudio.GetPlayTime("One") > 41.55 and phases[2] == 26 then
			if not Sonido then
				Sonido = true
				Audio.PlaySound("gasterintrofast")
			end
			if NewAudio.GetPlayTime("One") <= 41.85 then
				FakeGB.xscale = 1 + 1.5*math.sin(math.rad(90/0.3*(NewAudio.GetPlayTime("One") - 41.55)))
			else
				FakeGB.xscale = 2.5
				phases[2] = 27
			end
		elseif NewAudio.GetPlayTime("One") > 42.05 and phases[2] == 27 then
			if not Creado then
				NewAudio.CreateChannel("BRR")
				NewAudio.PlaySound("BRR", "gastervibration", true, 0.75)
				Creado = true
			end
			if NewAudio.GetPlayTime("One") <= 42.92 then
				FakeGB.MoveTo(320 + math.random(4, -4), 290 + math.random(4, -4))
			else
				FakeGB.Remove()
				FakeGB = nil
				Black = CreateSprite("Rotatory Arena Pixel", "Top")
				Black.color = {0,0,0}
				Black.Scale(640, 480)
				Black.MoveTo(320, 240)
				FakeLenght[1].Remove()
				FakeLenght2[1].Remove()
				FakeLenght[2].Scale(114, 490)
				FakeLenght2[2].Scale(104, 480)
				FakeLenght[2].MoveTo(FakeArena1.x, 240)
				FakeLenght2[2].MoveTo(FakeArena1.x, 240)
				FakeLenght[2].alpha = 0
				FakeLenght2[2].alpha = 0
				NewAudio.Stop("BRR")
				NewAudio.DestroyChannel("BRR")
				NewAudio.SetVolume("One", 0)
				Encounter.Call("AttackAnim", 2)
				Audio.PlaySound("st")
				FakeArena.Resize(600, 440)
				AuxY = 15
				FalseY = newpY
				state = 0
				Player.sprite.color = {1,0,0}
				Player.sprite.rotation = 0
				phases[1] = 30
				phases[2] = 28
			end
		elseif NewAudio.GetPlayTime("One") > 43.43 and phases[2] == 28 then
			for i=1,8 do
				table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Animacion = {DatosIniciales = {X = 320 - 640*math.sin(math.rad(45*i)), Y = 240 + 640*math.cos(math.rad(45*i)), rotation = 45*i}, DatosFinales = {X = 320 - 120*math.sin(math.rad(45*i)), Y = 240 + 120*math.cos(math.rad(45*i)), rotation = 45*i}, VelAppearing = 24}, Delay = 20, Duration = 40, NoDamage = true, NoSound = true})
			end
			GBPaps[1].Loud = true
			GBPaps[1].NoSound = nil
			Audio.PlaySound("gasterintro")
			Audio.PlaySound("gasterintro2")
			phases[2] = 29
		elseif NewAudio.GetPlayTime("One") > 43.45 and phases[2] == 29 then
			if not contador then
				contador = 0
			end
			if NewAudio.GetPlayTime("One") > 43.45 + 0.02*contador and contador <= 2 then
				Audio.PlaySound("gasterintro")
				Audio.PlaySound("gasterintro2")
				contador = contador + 1
			elseif contador > 2 then
				contador = 0
				phases[2] = 30
			end
		elseif NewAudio.GetPlayTime("One") > 44.3 and phases[2] == 30 then
			NewAudio.SetVolume("One", 0)
			Black.alpha = 1
			Audio.PlaySound("st")
			FakeArena.Resize(390, 115)
			AuxY = 90
			state = 11
			Player.sprite.color = {0,60/255,1}
			for i=1,#GBPaps do
				GBPaps[i - tableaux].Sprite.Remove()
				if GBPaps[i - tableaux].Laser then
					GBPaps[i - tableaux].Laser.Misil.Remove()
				end
				table.remove(GBPaps, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			if Fuerte then
				NewAudio.Stop("Loud1")
				NewAudio.Stop("Loud2")
				NewAudio.Stop("Loud3")
				NewAudio.Stop("Loud4")
				NewAudio.Stop("Loud5")
				NewAudio.Stop("Loud6")
				NewAudio.Stop("Loud7")
				NewAudio.Stop("Loud8")
				NewAudio.DestroyChannel("Loud1")
				NewAudio.DestroyChannel("Loud2")
				NewAudio.DestroyChannel("Loud3")
				NewAudio.DestroyChannel("Loud4")
				NewAudio.DestroyChannel("Loud5")
				NewAudio.DestroyChannel("Loud6")
				NewAudio.DestroyChannel("Loud7")
				NewAudio.DestroyChannel("Loud8")
				Fuerte = nil
			end
			phases[2] = 31
		elseif NewAudio.GetPlayTime("One") > 44.6 and phases[2] == 31 then
			Black.alpha = 0
			Blacks = {CreateSprite("Rotatory Arena Pixel","Top"), CreateSprite("Rotatory Arena Pixel","Top")}
			Blacks[1].color = {0,0,0}
			Blacks[2].color = {0,0,0}
			Blacks[1].Scale(120, 125)
			Blacks[2].Scale(120, 125)
			Blacks[1].MoveTo(60, 152.5)
			Blacks[2].MoveTo(580, 152.5)
			SX = 320
			SY = 70.5
			BFX = 87
			BFY = 27
			BAX = 240
			BAY = 27
			BIX = 400
			BIY = 27
			BMX = 555
			BMY = 27
			PapsX = 320
			PapsY = 240
			Audio.PlaySound("st")
			Audio.PlaySound("ding")
			NewAudio.SetVolume("One", 1)
			jump = 0
			newpX = 0
			newpY = -50
			PosX = newpX
			PosY = newpY
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 520, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 534, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 548, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 562, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 576, 150), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 100, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 120, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 106, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 92, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 78, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 45, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos2, {Body = CreateProjectileAbs("Bullets/Bones/Body", 64, 150), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Longitud = 100, Vel = 5, Mayor = 517.5, Menor = 0})
			phases[2] = 32
		elseif NewAudio.GetPlayTime("One") > 45.35 and phases[2] == 32 then
			Black.alpha = 1
			Blacks[1].Remove()
			Blacks[2].Remove()
			Blacks = nil
			Audio.PlaySound("st")
			NewAudio.SetVolume("One", 0)
			for i=1,#Huesos2 do
				Huesos2[i - tableaux].Body.Remove()
				Huesos2[i - tableaux].Head.Remove()
				Huesos2[i - tableaux].Legs.Remove()
				table.remove(Huesos2, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			Player.sprite.rotation = 180
			state = 10
			FakeArena.ResizeImmediate(104, 104)
			AuxY = 18
			BFY = -50
			BAY = -50
			BIY = -50
			BMY = -50
			SY = -100
			PapsY = 600
			phases[2] = 33
		elseif NewAudio.GetPlayTime("One") > 45.6 and phases[2] == 33 then
			Black.alpha = 0
			jump = 0
			newpX = 0
			newpY = FalseY
			PosY = newpY
			FalseY = nil
			FakeLenght[2].alpha = 1
			FakeLenght2[2].alpha = 1
			table.insert(GBPaps, {Sprite = CreateSprite("Bullets/GB Papyrus/0","BelowBullet"), Scale = 2.5, X = 320, Y = 290, Delay = 0, Duration = 40, NoDamage = true, Controler = true})
			phases[2] = 34
		elseif NewAudio.GetPlayTime("One") > 45.85 and phases[2] == 34 then
			Black.alpha = 1
			for i=1,#GBPaps do
				GBPaps[i - tableaux].Sprite.Remove()
				if GBPaps[i - tableaux].Laser then
					GBPaps[i - tableaux].Laser.Misil.Remove()
				end
				table.remove(GBPaps, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			if Controlando then
				NewAudio.Stop("Controlador")
				NewAudio.DestroyChannel("Controlador")
				Controlando = nil
			end
			NewAudio.SetVolume("One", 0)
			Audio.PlaySound("st")
			state = 11
			Player.sprite.rotation = 0
			FakeLenght[2].Remove()
			FakeLenght2[2].Remove()
			FakeLenght = nil
			FakeLenght2 = nil
			phases[2] = 35
		elseif NewAudio.GetPlayTime("One") > 46 and phases[2] == 35 then
			Black.Remove()
			Black = nil
			jump = 45
			newpX = 0
			newpY = -30
			PosX = newpX
			PosY = newpY
			SY = 70.5
			BFY = 27
			BAY = 27
			BIY = 27
			BMY = 27
			PapsY = 240
			AuxY = 90
			FakeArena.ResizeImmediate(390, 115)
			Audio.PlaySound("st")
			NewAudio.SetVolume("One", 1)
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 420, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 315, Longitud = 45, Delay = 0, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 434, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 329, Longitud = 45, Delay = 0, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 448, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 343, Longitud = 45, Delay = 0, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 462, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 357, Longitud = 45, Delay = 0, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 476, 150), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 371, Longitud = 100, Delay = 0, Vel = -5, Mayor = 640, Menor = 122.5})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 220, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 325, Longitud = 45, Delay = 20, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 206, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 311, Longitud = 45, Delay = 20, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 192, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 297, Longitud = 45, Delay = 20, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 178, 122.5), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 283, Longitud = 45, Delay = 20, Vel = 5, Mayor = 517.5, Menor = 0})
			table.insert(Huesos6, {Body = CreateProjectileAbs("Bullets/Bones/Body", 164, 150), Head = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Legs = CreateProjectileAbs("Bullets/Bones/Head", 0, 0), Pos = 269, Longitud = 100, Delay = 20, Vel = 5, Mayor = 517.5, Menor = 0})
			phases[2] = 36
		elseif NewAudio.GetPlayTime("One") > 47.3 and phases[2] == 36 then
			if NewAudio.GetPlayTime("One") <= 47.8 then
				FakeArena.Resize(390 - 235/0.5*(NewAudio.GetPlayTime("One") - 47.3), 115 + 15/0.5*(NewAudio.GetPlayTime("One") - 47.3), true)
			else
				FakeArena.Resize(155, 130, true)
				phases[2] = 37
			end
		elseif NewAudio.GetPlayTime("One") > 47.8 and phases[2] == 37 then
			if NewAudio.GetPlayTime("One") <= 48.3 then
				FakeArena.Resize(155 + 175*math.sin(math.rad(90/0.5*(NewAudio.GetPlayTime("One") - 47.8))), 130 - 15*math.sin(math.rad(180/0.5*(NewAudio.GetPlayTime("One") - 47.8))), true)
			else
				FakeArena.Resize(330, 130, true)
				phases[2] = 38
			end
		elseif (NewAudio.GetPlayTime("One") > 48.8 and phases[2] == 38) or NewAudio.isStopped("One") then
			Finalizar = true
		end
	end
	if speed then
		PapsX = PapsX + ((speed or 0)/10)
		speed = speed - 2
		if PapsX <= -200 then
			speed = nil
		end
	end
	if Warn then
		Warn.alpha = 0.2 + 0.1*math.sin(math.rad(1080*NewAudio.GetPlayTime("One")))
	end
	FakeArena.MoveTo(AuxX, AuxY, true)
	Encounter.Call("PapsMoveTo", {PapsX, PapsY})
	Encounter.Call("StatusMoveTo", {SX, SY})
	Encounter.Call("ButtonMoveTo", {"Fight", BFX, BFY})
	Encounter.Call("ButtonMoveTo", {"Act", BAX, BAY})
	Encounter.Call("ButtonMoveTo", {"Item", BIX, BIY})
	Encounter.Call("ButtonMoveTo", {"Mercy", BMX, BMY})
	if Black1 and Black2 then
		Black1.MoveTo(25, 72)
		Black2.MoveTo(640 - 25, 72)
	end
	for i=1,#GBPaps do
		local gb = GBPaps[i - tableaux]
		if not gb.X then
			gb.X = gb.Sprite.x
		end
		if not gb.Y then
			gb.Y = gb.Sprite.y
		end
		gb.Sprite.xscale = (gb.Scale or 1)
		if gb.Animacion then
			if not gb.Animacion.timer then
				gb.Animacion.timer = 0
			end
			gb.Animacion.timer = gb.Animacion.timer + 1
			gb.X = gb.Animacion.DatosIniciales.X + (gb.Animacion.DatosFinales.X - gb.Animacion.DatosIniciales.X)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Y = gb.Animacion.DatosIniciales.Y + (gb.Animacion.DatosFinales.Y - gb.Animacion.DatosIniciales.Y)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			gb.Sprite.MoveTo(gb.X, gb.Y)
			while gb.Animacion.DatosIniciales.rotation >= 360 or gb.Animacion.DatosIniciales.rotation < 0 do
				if gb.Animacion.DatosIniciales.rotation < 0 then
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation + 360
				else
					gb.Animacion.DatosIniciales.rotation = gb.Animacion.DatosIniciales.rotation - 360
				end
			end
			while gb.Animacion.DatosFinales.rotation >= 360 or gb.Animacion.DatosFinales.rotation < 0 do
				if gb.Animacion.DatosFinales.rotation < 0 then
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation + 360
				else
					gb.Animacion.DatosFinales.rotation = gb.Animacion.DatosFinales.rotation - 360
				end
			end
			if gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation <= 180 and gb.Animacion.DatosFinales.rotation - gb.Animacion.DatosIniciales.rotation >= -180 then
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (gb.Animacion.DatosIniciales.rotation - gb.Animacion.DatosFinales.rotation)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30))))
			else
				gb.Sprite.rotation = gb.Animacion.DatosIniciales.rotation - (360 - (gb.Animacion.DatosFinales.rotation - 180 + gb.Animacion.DatosIniciales.rotation - 180)*math.sin(math.rad(gb.Animacion.timer*(90/(gb.Animacion.VelAppearing or 30)))))
			end
			if gb.Animacion.timer >= (gb.Animacion.VelAppearing or 30) then
				gb.Animacion = nil
				gb.Done = true
			end
		else
			if gb.Rotation and not gb.Done then
				gb.Sprite.rotation = gb.Rotation
			end
			gb.Delay = gb.Delay - 1
		end
		if gb.Vel then
			gb.X = gb.X - gb.Vel*math.sin(math.rad(gb.Sprite.rotation))
			gb.Y = gb.Y + gb.Vel*math.cos(math.rad(gb.Sprite.rotation))
			gb.Vel = gb.Vel*1.1
			if gb.X < -100 or gb.X > 740 or gb.Y < -100 or gb.Y > 580 then
				gb.Vel = 0
			end
		end
		gb.Sprite.MoveTo(gb.X, gb.Y)
		if gb.Delay < 0 then
			if gb.Delay == -1 then
				gb.Sprite.Set("Bullets/GB Papyrus/1")
				gb.Vel = 2
				if not gb.NoSound then
					if gb.Loud then
						NewAudio.CreateChannel("Loud1")
						NewAudio.CreateChannel("Loud2")
						NewAudio.CreateChannel("Loud3")
						NewAudio.CreateChannel("Loud4")
						NewAudio.CreateChannel("Loud5")
						NewAudio.CreateChannel("Loud6")
						NewAudio.CreateChannel("Loud7")
						NewAudio.CreateChannel("Loud8")
						NewAudio.PlaySound("Loud1", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud2", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud3", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud4", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud5", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud6", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud7", "gasterfire", false, 0.75)
						NewAudio.PlaySound("Loud8", "gasterfire", false, 0.75)
						Fuerte = true
					elseif gb.Controler then
						NewAudio.CreateChannel("Controlador")
						NewAudio.PlaySound("Controlador", "gasterfire", false, 1)
						Controlando = true
					else
						Audio.PlaySound("gasterfire")
					end
				end
			elseif gb.Delay <= -2 then
				Misc.ShakeScreen(1, 8, false)
				if gb.Duration > 0 then
					gb.Duration = gb.Duration - 1
					if not gb.Laser then
						gb.Laser = {Misil = CreateProjectileAbs("Bullets/GB Laser", gb.X + (640 + 26*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + 26*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)), "Top")}
						gb.Laser.Misil.sprite.xscale = 0
						gb.Laser.Misil.sprite.rotation = gb.Sprite.rotation
						gb.Laser.Scale = 0
						if gb.NoDamage then
							gb.Laser.Misil.SetVar("No Damage", true)
						end
					else
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + 26*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + 26*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						if gb.Laser.Misil.sprite.xscale < 0.9*gb.Sprite.xscale and gb.Laser.Scale == 0 then
							gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale + 0.1*gb.Sprite.xscale
						else
							gb.Laser.Scale = gb.Laser.Scale + 50
							gb.Laser.Misil.sprite.xscale = 0.9*gb.Sprite.xscale + 0.1*gb.Sprite.xscale*math.sin(math.rad(gb.Laser.Scale))
						end
					end
				else
					gb.Laser.Misil.SetVar("No Damage", true)
					if gb.Laser.Misil.sprite.xscale > 0 then
						gb.Laser.Misil.MoveToAbs(gb.X + (640 + 26*gb.Sprite.yscale)*math.sin(math.rad(gb.Sprite.rotation)), gb.Y - (640 + 26*gb.Sprite.yscale)*math.cos(math.rad(gb.Sprite.rotation)))
						gb.Laser.Misil.sprite.xscale = gb.Laser.Misil.sprite.xscale - 0.05*gb.Sprite.xscale
						gb.Laser.Misil.sprite.alpha = gb.Laser.Misil.sprite.xscale
					else
						gb.Laser.Misil.Remove()
						gb.Sprite.Remove()
						gb = nil
						table.remove(GBPaps, i - tableaux)
						tableaux = tableaux + 1
					end
				end
			end
		end
	end
	tableaux = 0
	for i=1,#Huesos1 do
		local Datos = Huesos1[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		if not Datos.DesTimer then
			Datos.DesTimer = 0
		end
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		if NewAudio.GetPlayTime("One") > Datos.Desaparecer then
			Datos.DesTimer = Datos.DesTimer + 1
			Datos.Body.MoveToAbs(Datos.X, Datos.Y + 145*math.cos(math.rad(90/30*Datos.DesTimer)))
			if Datos.DesTimer > 60 then
				Datos.Body.Remove()
				Datos = nil
				table.remove(Huesos1, i - tableaux)
				tableaux = tableaux + 1
			end
		elseif Datos.Timer <= Datos.Aparicion then
			Datos.Timer = Datos.Timer + 1
			Datos.Body.MoveToAbs(Datos.X, Datos.Y + 145*math.sin(math.rad(90/Datos.Aparicion*Datos.Timer)))
		else
			Datos.Body.MoveToAbs(Datos.X, Datos.Y + 145)
		end
	end
	tableaux = 0
	for i=1,#Huesos2 do
		local Datos = Huesos2[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		if not Datos.Color then
			Datos.Color = {1,1,1}
		end
		Datos.Body.sprite.yscale = Datos.Longitud
		Datos.Legs.sprite.rotation = 180
		Datos.X = Datos.X + Datos.Vel
		Datos.Body.sprite.color = Datos.Color
		Datos.Head.sprite.color = Datos.Color
		Datos.Legs.sprite.color = Datos.Color
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Longitud/2 + 2.5)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Longitud/2 - 2.5)
		if Datos.Tipo then
			Datos.Body.SetVar("tipo", Datos.Tipo)
			Datos.Head.SetVar("tipo", Datos.Tipo)
			Datos.Legs.SetVar("tipo", Datos.Tipo)
		end
		if Datos.X > Datos.Mayor or Datos.X < Datos.Menor then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Huesos2, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Huesos3 do
		local Datos = Huesos3[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		Datos.X = Datos.X + Datos.Vel
		if Datos.X < 240 then
			Datos.Longitud = math.max(Datos.Longitud - 6, 36)
			Datos.Y = Datos.Longitud/2
		end
		Datos.Body.sprite.yscale = Datos.Longitud
		Datos.Legs.sprite.rotation = -180
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Longitud/2 + 2.5)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Longitud/2 - 2.5)
		if Datos.X > Datos.Mayor or Datos.X < Datos.Menor then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Huesos3, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Huesos4 do
		local Datos = Huesos4[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		if Datos.Timer ~= 20 then
			Datos.Timer = Datos.Timer + 1
		end
		if Datos.Timer <= 20 then
			Datos.Y = Datos.PosY - Datos.Direction/20*Datos.Timer
			Datos.Longitud = 118/20*Datos.Timer
		elseif Datos.Timer <= 61 then
			Datos.Body.sprite.color = {1, 150/255, 0}
			Datos.Head.sprite.color = {1, 150/255, 0}
			Datos.Legs.sprite.color = {1, 150/255, 0}
			Datos.Body.SetVar("tipo", "Orange")
			Datos.Head.SetVar("tipo", "Orange")
			Datos.Legs.SetVar("tipo", "Orange")
			Datos.X = Datos.PosX + 398 - 398*math.cos(math.rad(90/40*(Datos.Timer - 21)))
		elseif Datos.Timer > 65 and Datos.Timer <= 106 then
			if Datos.Timer == 66 and not Dinged then
				Audio.PlaySound("ding")
				Dinged = true
			end
			Datos.Body.sprite.color = {33/255, 197/255, 1}
			Datos.Head.sprite.color = {33/255, 197/255, 1}
			Datos.Legs.sprite.color = {33/255, 197/255, 1}
			Datos.Body.SetVar("tipo", "Blue")
			Datos.Head.SetVar("tipo", "Blue")
			Datos.Legs.SetVar("tipo", "Blue")
			Datos.X = Datos.PosX + 398 - 243/40*(Datos.Timer - 66)
		elseif Datos.Timer > 65 and Datos.Timer <= 142 then
			Datos.X = Datos.PosX + 155 - 24*math.sin(math.rad(90/18*(Datos.Timer - 106)))
		elseif Datos.Timer > 65 and Datos.Timer <= 182 then
			Datos.X = Datos.PosX + 155 + 500/40*(Datos.Timer - 142)
		end
		Datos.Body.sprite.yscale = Datos.Longitud
		Datos.Legs.sprite.rotation = -180
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Longitud/2 + 2.5)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Longitud/2 - 2.5)
		if Datos.Timer > 181 then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Huesos4, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Huesos5 do
		local Datos = Huesos5[i - tableaux]
		Datos.Y = Datos.Y + 5
		Datos.Bound.MoveTo(320, 75)
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		if Datos.Y > 339 then
			Datos.Body.sprite.layer = "BulletPool"
			Datos.Body.Remove()
			Datos.Bound.Remove()
			table.remove(Huesos5, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Huesos6 do
		local Datos = Huesos6[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Body.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Body.absy
		end
		Datos.Body.sprite.yscale = Datos.Longitud
		Datos.Legs.sprite.rotation = 180
		Datos.X = Datos.X + Datos.Vel
		if (Datos.X > Datos.Pos and Datos.Vel > 0) or (Datos.X < Datos.Pos and Datos.Vel < 0) then
			if Datos.Delay > 0 then
				Datos.Delay = Datos.Delay - 1
				Datos.X = Datos.X - Datos.Vel
			else
				Datos.Body.sprite.color = {1, 150/255, 0}
				Datos.Head.sprite.color = {1, 150/255, 0}
				Datos.Legs.sprite.color = {1, 150/255, 0}
				Datos.Body.SetVar("tipo", "Orange")
				Datos.Head.SetVar("tipo", "Orange")
				Datos.Legs.SetVar("tipo", "Orange")
			end
		end
		Datos.Body.MoveToAbs(Datos.X, Datos.Y)
		Datos.Head.MoveToAbs(Datos.X, Datos.Y + Datos.Longitud/2 + 2.5)
		Datos.Legs.MoveToAbs(Datos.X, Datos.Y - Datos.Longitud/2 - 2.5)
		if Datos.X > Datos.Mayor or Datos.X < Datos.Menor then
			Datos.Body.Remove()
			Datos.Head.Remove()
			Datos.Legs.Remove()
			table.remove(Huesos6, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#SpecialBones do
		local Datos = SpecialBones[i - tableaux]
		if not Datos.X then
			Datos.X = Datos.Bullet.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Bullet.absy
		end
		Datos.Bullet.sprite.rotation = Datos.Rotation
		Datos.X = Datos.X + Datos.Vel
		Datos.Bullet.MoveToAbs(Datos.X, Datos.Y)
		if Datos.Generar then
			if Datos.X <= 598 and Datos.Generar > 0 then
				table.insert(SpecialBones, {Bullet = CreateProjectileAbs("Bullets/Bones/BoneWay", 1174, 75), Vel = -12, Generar = Datos.Generar - 1, Rotation = 0, Delete = -270})
				Datos.Generar = nil
			end
		end
		if Datos.X < Datos.Delete then
			Datos.Bullet.Remove()
			table.remove(SpecialBones, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	if state == 1 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 4
		end
		if Input.Left > 0 then
			newpX = newpX - 4
		end
		if newpY + AuxY + Arena.height/2 < AuxY + 15 then
			newpY = -Arena.height/2 + 8
			jump = 0
			state = 2
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Up < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.max(newpY + (jump/10), -Arena.height/2 + 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 2 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 4
		end
		if Input.Left > 0 then
			newpX = newpX - 4
		end
		if newpY + AuxY + Arena.height/2 < AuxY + 15 then
			if Input.Up > 0 then
				jump = maxjump
			else
				newpY = -Arena.height/2 + 8
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Up < 0 and jump > 6 then
			jump = 4
		end
		newpY = math.max(newpY + (jump/10), -Arena.height/2 + 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 3 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY + AuxY + Arena.height/2 < AuxY + 15 then
			newpY = -Arena.height/2 + 8
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Up < 0 and jump > 6 then
			jump = 4
		end
		newpY = math.max(newpY + (jump/10), -Arena.height/2 + 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 4 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 4
		end
		if Input.Left > 0 then
			newpX = newpX - 4
		end
		if newpY + AuxY + Arena.height/2 < AuxY + 15 and jump <= 0 then
			newpY = -Arena.height/2 + 8
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if newpY < Arena.height/2 - 8 or jump <= 0 then
			if jump <= 0 then
				newpY = math.max(newpY + (jump/60), -Arena.height/2 + 8)
			else
				newpY = math.max(newpY + (jump/10), -Arena.height/2 + 8)
			end
		elseif jump > 0 then
			newpY = Arena.height/2 - 8
			jump = 0
		end
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 5 then -- Up
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY + AuxY + Arena.height/2 > AuxY + Arena.height - 5 then
			newpY = Arena.height/2 - 8
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Down < 0 and jump > 6 then
			jump = 4
		end
		newpY = math.min(newpY - (jump/10), Arena.height/2 - 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 6 then -- Right
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX + AuxX > AuxX + Arena.width/2 - 10 then
			newpX = Arena.width/2 - 8
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Left < 0 and jump > 6 then
			jump = 4
		end
		newpX = math.min(newpX - (jump/10), Arena.width/2 - 8)
		if newpY < -Arena.height/2 + 8 then
			newpY = -Arena.height/2 + 8
		elseif newpY > Arena.height/2 - 8 then
			newpY = Arena.height/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 7 then -- Left
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX + AuxX < AuxX - Arena.width/2 + 10 then
			newpX = -Arena.width/2 + 8
			jump = 0
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Right < 0 and jump > 6 then
			jump = 4
		end
		newpX = math.max(newpX + (jump/10), -Arena.width/2 + 8)
		if newpX + FakeArena.x <= 45 then
			state = 8
			jump = 10
			Limite = -275
			Player.sprite.rotation = 90
			phases[2] = 23
		end
		if newpY < -Arena.height/2 + 8 then
			newpY = -Arena.height/2 + 8
		elseif newpY > Arena.height/2 - 8 then
			newpY = Arena.height/2 - 8
		end
		PosX = newpX
		PosY = newpY
	end
	if state == 8 then -- Right
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if newpX + AuxX > AuxX + Limite - 2 then
			newpX = Limite
			jump = -40
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Left < 0 and jump > 3 then
			jump = 2
		end
		newpX = math.min(newpX - (jump/10), Limite)
		if newpY < -Arena.height/2 + 8 then
			newpY = -Arena.height/2 + 8
		elseif newpY > Arena.height/2 - 8 then
			newpY = Arena.height/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 9 then -- Left
		if Input.Up > 0 then
			newpY = newpY + 3
		end
		if Input.Down > 0 then
			newpY = newpY - 3
		end
		if jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if jump <= 0 then
			state = 10
		end
		newpX = math.max(newpX + (jump/10), -Arena.width/2 + 8)
		if newpY < -Arena.height/2 + 8 then
			newpY = -Arena.height/2 + 8
		elseif newpY > Arena.height/2 - 8 then
			newpY = Arena.height/2 - 8
		end
		PosX = newpX
		PosY = newpY
	end
	if state == 10 then -- Up
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY + AuxY + Arena.height/2 > AuxY + Arena.height - 5 then
			newpY = Arena.height/2 - 8
			jump = -40
		elseif jump < 3 and jump > -3 then
			jump = jump - 0.5
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 1.5
		else
			jump = (jump/1.001) - 1
		end
		if Input.Down < 0 and jump > 3 then
			jump = 2
		end
		newpY = math.min(newpY - (jump/10), Arena.height/2 - 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if state == 11 then -- Down
		if Input.Right > 0 then
			newpX = newpX + 3
		end
		if Input.Left > 0 then
			newpX = newpX - 3
		end
		if newpY + AuxY + Arena.height/2 < AuxY + 15 then
			if Input.Up > 0 then
				jump = maxjump + 15
			else
				newpY = -Arena.height/2 + 8
				jump = 0
			end
		elseif jump < 3 and jump > -3 then
			jump = jump - 1
		elseif jump < -3 and jump > -10 then
			jump = -10
		elseif jump < -3 then
			jump = jump - 3
		else
			jump = (jump/1.001) - 2
		end
		if Input.Up < 0 and jump > 6 then
			jump = 4
		end
		newpY = math.max(newpY + (jump/10), -Arena.height/2 + 8)
		if newpX < -Arena.width/2 + 8 then
			newpX = -Arena.width/2 + 8
		elseif newpX > Arena.width/2 - 8 then
			newpX = Arena.width/2 - 8
		end
		PosX = newpX
		PosY = newpY
    end
	if FakeLenght and FakeLenght2 and phases[1] >= 29 then
		FakeLenght[2].MoveTo(FakeArena1.x, 240)
		FakeLenght2[2].MoveTo(FakeArena1.x, 240)
	end
	DialogUpdate()
	FakeArena.Update()
	if Finalizar then
		for i=1,#GBPaps do
			GBPaps[i - tableaux].Sprite.Remove()
			table.remove(GBPaps, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		FakeArena.Remove()
		EndWave()
	end
end

function OnHit(bullet)
	if not bullet.GetVar("No Damage") and not Player.isHurting then
		if bullet.GetVar("tipo") then
			if bullet.GetVar("tipo") == "Blue" and (jump ~= 0 or Input.Left > 0 or Input.Right > 0) then
				if Player.hp > 1 then
					Player.hp = Player.hp - 1
					Encounter.Call("AddKR", 1)
				else
					CauseDeath()
				end
				Player.Hurt(0, 2/60)
				Encounter["NOHIT"] = nil
			elseif bullet.GetVar("tipo") == "Orange" and (jump == 0 and Input.Left == 0 and Input.Right == 0) then
				if Player.hp > 1 then
					Player.hp = Player.hp - 1
					Encounter.Call("AddKR", 1)
				else
					CauseDeath()
				end
				Player.Hurt(0, 2/60)
				Encounter["NOHIT"] = nil
			end
		else
			if Player.hp > 1 then
				Player.hp = Player.hp - 1
				Encounter.Call("AddKR", 1)
			else
				CauseDeath()
			end
			Player.Hurt(0, 2/60)
			Encounter["NOHIT"] = nil
		end
	end
end

function CauseDeath()
	for i=1,#GBPaps do
		GBPaps[i - tableaux].Sprite.Remove()
		table.remove(GBPaps, i - tableaux)
		tableaux = tableaux + 1
	end
	tableaux = 0
	if Black1 then
		Black1.Remove()
		Black1 = nil
	end
	if Black2 then
		Black2.Remove()
		Black2 = nil
	end
	if FakeLenght then
		if FakeLenght[1].isactive then
			FakeLenght[1].Remove()
		end
		FakeLenght[2].Remove()
		FakeLenght = nil
	end
	if FakeLenght2 then
		if FakeLenght2[1].isactive then
			FakeLenght2[1].Remove()
		end
		FakeLenght2[2].Remove()
		FakeLenght2 = nil
	end
	if BubbleS then
		BubbleS.Remove()
		BubbleS = nil
	end
	if Warn then
		Warn.Remove()
		Warn = nil
	end
	if FakeGB then
		FakeGB.Remove()
		FakeGB = nil
	end
	if Black then
		Black.Remove()
		Black = nil
	end
	if Blacks then
		Blacks[1].Remove()
		Blacks[2].Remove()
		Blacks = nil
	end
	FakeArena.Remove()
	Bubble("", "", "", "", "", "", 1)
	Encounter["X"] = Player.absx
	Encounter["Y"] = Player.absy
	Encounter["nextwaves"] = {"Game Over"}
	State("ACTIONSELECT")
	State("DEFENDING")
end