timer = 0
timerF = 0
dir = math.random(2)

state = 1
maxjump = 40
jump = 0
newpX = 320
newpY = 500
tableaux = 0

Black = CreateSprite("Bullets/Bones/Body","BelowPlayer")
Black.MoveTo(320, 240)
Black.Scale(660/5, 500)
Black.color = {0, 0, 0}

NewAudio.Stop("One")
NewAudio.Stop("Loop")
Encounter["GameMusic"] = "None"

Player.SetControlOverride(false)

Humito = {}

function RecolorSoul()
	if state == 1 then
		Player.sprite.color = {0,60/255,1}
		Player.sprite.rotation = 0
	end
end

RecolorSoul()

function Update()
	if state == 1 then
		if newpY <= 8 then
			timer = timer + 1
			if timer <= 60 then
				if timer == 1 then
					Message = CreateSprite("Minecraft/"..GetAlMightyGlobal("Idioma").."/Message","BelowPlayer")
					Message.MoveTo(Message.width/2 + 6, 40)
					Red = CreateSprite("Bullets/Bones/Body","BelowPlayer")
					Red.MoveTo(320, 240)
					Red.Scale(660/5, 500)
					Red.color = {1, 0, 0}
					Red.alpha = 0.4
					YouDied = CreateSprite("Minecraft/"..GetAlMightyGlobal("Idioma").."/You died!","Top")
					YouDied.MoveTo(320, 300)
					Respawn = CreateSprite("Minecraft/"..GetAlMightyGlobal("Idioma").."/Respawn 0","Top")
					Respawn.MoveTo(320, 160)
					Respawn.color = {0.8, 0.8, 0.8}
					if GetAlMightyGlobal("Idioma") == "Russian" then
						Click = CreateSprite("Minecraft/Click Russian","Top")
					else
						Click = CreateSprite("Minecraft/Click","Top")
					end
					Click.MoveTo(320, 220)
					Click.alpha = 0
					Flecha = CreateSprite("Minecraft/Flechita","Top")
					Flecha.MoveTo(320, 200)
					Flecha.alpha = 0
					Audio.PlaySound("hurt")
					Player.sprite.color = {169/255, 60/255, 1}
					Misc.ShakeScreen(30, 20, true)
				elseif timer == 30 and string.sub(GetAlMightyGlobal("Archivimentazo"), 14, 14) == "0" then
					SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 13).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 15))
					Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 14}
				end
				if dir == 1 then
					Player.sprite.rotation = 90*math.sin(math.rad(90/60*timer))
					newpX = 312 + 8*math.cos(math.rad(Player.sprite.rotation))
					newpY = 8 - 8*math.sin(math.rad(Player.sprite.rotation))
				else
					Player.sprite.rotation = -90*math.sin(math.rad(90/60*timer))
					newpX = 328 - 8*math.cos(math.rad(Player.sprite.rotation))
					newpY = 8 + 8*math.sin(math.rad(Player.sprite.rotation))
				end
			elseif timer == 61 then
				for i=1,3 do
					table.insert(Humito, {Sprite = CreateSprite("Minecraft/Smoke 1", "BelowBullet"), X = Player.absx + math.random(-1, 1), Y = 8 + math.random(-1, 1), Rotation = math.random(0, 180), Vel = 0.1*math.random(2, 4)})
				end
				Player.sprite.alpha = 0
			elseif timer > 300 and Message.alpha > 0 then
				Message.alpha = Message.alpha - 0.02
			end
			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
		newpY = math.max(newpY + (jump/10), 0)
		Player.MoveToAbs(newpX, newpY, true)
	end
	if Click and Click.alpha > 0 then
		Click.alpha = Click.alpha - 0.02
	end
	if Flecha then
		timerF = timerF + 2
		Flecha.MoveTo(320, 195 + 5*math.sin(math.rad(timerF)))
		if Flecha.alpha > 0 then
			Flecha.alpha = Flecha.alpha - 0.02
		end
	end
	if Respawn and not clicked then
		if Input.MousePosX >= 179 and Input.MousePosX <= 461 and Input.MousePosY >= 147 and Input.MousePosY <= 174 then
			Respawn.color = {1, 1, 1}
			if Input.GetKey("Mouse0") > 0 then
				Respawn.Set("Minecraft/"..GetAlMightyGlobal("Idioma").."/Respawn 1")
				clicked = 0
			end
		else
			Respawn.color = {0.8, 0.8, 0.8}
		end
		if Input.Confirm == 1 then
			Click.alpha = 1
			Flecha.alpha = 1
		end
	elseif Respawn and clicked then
		clicked = clicked + 1
		if clicked == 5 then
			Respawn.Set("Minecraft/"..GetAlMightyGlobal("Idioma").."/Respawn 0")
			Respawn.color = {0.8, 0.8, 0.8}
		end
		fade = true
	end
	for i=1,#Humito do
		local Datos = Humito[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 20
		end
		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.Sprite.MoveTo(Datos.X, Datos.Y)
		Datos.Timer = Datos.Timer + 1
		if Datos.Timer == 120 then
			Datos.Sprite.Remove()
			table.remove(Humito, i - tableaux)
			tableaux = tableaux + 1
		elseif Datos.Timer%20 == 0 then
			Datos.Sprite.Set("Minecraft/Smoke "..Datos.Timer/20)
		end
	end
	tableaux = 0
	if fade then
		if not Black2 then
			Black2 = CreateSprite("Bullets/Bones/Body","Top")
			Black2.MoveTo(320, 240)
			Black2.Scale(640/5, 480)
			Black2.color = {0, 0, 0}
			Black2.alpha = 0
		end
		Black2.alpha = Black2.alpha + 0.01
		if Black2.alpha >= 1 then
			Black.Remove()
			Black2.Remove()
			Message.Remove()
			Red.Remove()
			YouDied.Remove()
			Respawn.Remove()
			Click.Remove()
			Flecha.Remove()
			for i=1,#Humito do
				Humito[i - tableaux].Sprite.Remove()
				table.remove(Humito, i - tableaux)
				tableaux = tableaux + 1
			end
			tableaux = 0
			Encounter.Call("Reset")
		end
	end
end