Arena.ResizeImmediate(565, 130)
timer = 0
tableaux = 0
Player.sprite.alpha = 0

require "Dialogs"

Black = CreateSprite("Pixel","Top")
Black.Scale(640, 480)
Black.color = {0, 0, 0}
Black.MoveTo(320, 240)
Heart = CreateSprite("Undertale/Game Over/Soul","Top")
Heart.color = Player.sprite.color
Heart.MoveTo(Player.absx, Player.absy)

Shards = {}

function Update()
	DialogUpdate()
	timer = timer + 1
	if timer == 75 then
		Heart.Set("Undertale/Game Over/Soul Dead")
		Audio.PlaySound("lol You died")
	elseif timer == 150 then
		for i=1,6 do
			table.insert(Shards, {Sprite = CreateSprite("Soul Shards/1","Top"), X = math.random(-40, 40), Y = math.random(40)})
			Shards[i].Sprite.SetAnimation({"Soul Shards/1","Soul Shards/2","Soul Shards/3","Soul Shards/4"}, 1/6)
			Shards[i].Sprite.color = Heart.color
			Shards[i].Sprite.MoveTo(Heart.x, Heart.y)
		end
		Heart.Remove()
		Heart = nil
		Audio.PlaySound("Dead")
	elseif timer == 225 then
		NewAudio.CreateChannel("Game Over")
		NewAudio.PlaySound("Game Over", "Game Over", true, 1)
		if GetAlMightyGlobal("Idioma") == "Russian" then
			GameOver = CreateSprite("Undertale/Game Over/Game Over Russian","Top")
		else
			GameOver = CreateSprite("Undertale/Game Over/Game Over","Top")
		end
		GameOver.MoveTo(320, 360)
		GameOver.alpha = 0
	elseif timer >= 226 and timer < 301 then
		GameOver.alpha = (timer - 225)/75
	elseif timer == 350 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			Dialog("[noskip][voice:asgore][SetSpace:3]Todavía no puedes\rrendirte.", {X = 150, Y = 140}, nil, nil, 1)
		elseif GetAlMightyGlobal("Idioma") == "Russian" then
			Dialog("[noskip][voice:asgore][SetSpace:3]Ты не можешь\nсдаться сейчас...", {X = 150, Y = 140}, nil, nil, 1)
		else
			Dialog("[noskip][voice:asgore][SetSpace:3]You can't give up just\ryet.", {X = 150, Y = 140}, nil, nil, 1)
		end
		dialogo = 1
	end
	if dialogo and Dialogues[1] and not Dialogues[1].Activo then
		if dialogo == 1 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Dialog("[noskip][voice:asgore][SetSpace:3]Jugador.[w:30]\nMantente Determinado.", {X = 150, Y = 140}, nil, nil, 1)
			elseif GetAlMightyGlobal("Idioma") == "Russian" then
				Dialog("[noskip][voice:asgore][SetSpace:3]Игрок.[w:30]\nСохраняй Решимость...", {X = 150, Y = 140}, nil, nil, 1)
			else
				Dialog("[noskip][voice:asgore][SetSpace:3]Player.[w:30]\nStay Determined.", {X = 150, Y = 140}, nil, nil, 1)
			end
			dialogo = 2
		elseif dialogo == 2 then
			dialogo = 3
		elseif dialogo == 3 and Input.Confirm == 1 then
			dialogo = 4
		elseif dialogo == 4 then
			if GameOver.alpha > 0 then
				GameOver.alpha = GameOver.alpha - 0.01
				NewAudio.SetVolume("Game Over", GameOver.alpha)
			else
				NewAudio.Stop("Game Over")
				NewAudio.DestroyChannel("Game Over")
				GameOver.Remove()
				GameOver = nil
				dialogo = 5
			end
		elseif dialogo >= 5 and dialogo < 125 then
			dialogo = dialogo + 1
		elseif dialogo == 125 then
			Black.Remove()
			Black = nil
			Player.sprite.alpha = 1
			Player.sprite.color = {1,0,0}
			Encounter["nextwaves"] = {"Menu"}
			SetRealGlobal("Extras", 5)
			State("ACTIONSELECT")
			State("DEFENDING")
		end
	end
	for i=1,#Shards do
		local Datos = Shards[i - tableaux]
		Datos.Sprite.MoveTo(Datos.Sprite.x + Datos.X/10, Datos.Sprite.y + Datos.Y/10)
		Datos.Y = Datos.Y - 1
		if Datos.Sprite.y <= -10 then
			Datos.Sprite.Remove()
			Datos = nil
			table.remove(Shards, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
end