require "Dialogs"

Arena.ResizeImmediate(565, 130)
timerErr = -1

tableaux = 0
Crash = {}

function Update()
	if not tempStop and not tempStopUnskippeable then
		timerErr = timerErr + 1
	elseif Input.Confirm == 1 then
		tempStop = nil
	end
	if timerErr == 0 then
		NewAudio.SetVolume("One", 0)
		NewAudio.SetVolume("Loop", 0)
		Encounter["StopEncounter"] = true
		Audio.PlaySound("error")
		Error = CreateSprite("ERR", "Top")
		Error.MoveTo(320, 240)
		Dialog("[instant][color:000000]ERROR\rAttempt to show hitboxes failed[w:100000000000000000000] ", {X = Error.absx - 200, Y = Error.absy + 40}, nil, nil, 1)
		tempStop = true
		timerErr = 1
	elseif timerErr%2 == 0 and timerErr < 60 then
		Error = CreateSprite("ERR", "Top")
		Error.MoveTo(math.random(640), math.random(480))
		Dialog("[instant][color:000000]ERROR ERROR ERROR\rCan't show hitboxes in game[w:100000000000000000000] ", {X = Error.absx - 200, Y = Error.absy + 40}, nil, nil, 1*(timerErr/2))
	elseif timerErr == 60 then
		NewAudio.CreateChannel("Scream")
		NewAudio.PlaySound("Scream", "scream", false, 2)
		Screemer = CreateSprite("Screemer1","Top")
		Screemer.SetAnimation({"Screemer1","Screemer2","Screemer3","Screemer2"}, 0.05)
		Screemer.MoveTo(320,240)
		table.insert(Crash, Screemer)
		timerErr = 61
		tempStopUnskippeable = true
		if string.sub(GetAlMightyGlobal("Archivimentazo"), 18, 18) == "0" then
			SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 17).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 19))
			Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 18}
		end
	elseif timerErr == 120 then
		Misc.DestroyWindow()
	end
	if timerErr%2 == 0 then
		Audio.PlaySound("error")
	end
	for i=1,#Crash do
		local sprite = Crash[i - tableaux]
		sprite.xscale = sprite.xscale + 3/5
		sprite.yscale = sprite.yscale + 3/5
		if (sprite.xscale * 75) >= 1000 then
			NewAudio.Stop("Scream")
			NewAudio.PlaySound("Scream", "Distorsion", true, 1)
			sprite.Remove()
			BZZ = CreateSprite("Distorsion/1","Top")
			BZZ.SetAnimation({"Distorsion/1","Distorsion/2","Distorsion/3"}, 0.04)
			BZZ.MoveTo(320, 240)
			BZZ.Scale(2,2)
			table.remove(Crash, i - tableaux)
			tempStopUnskippeable = nil
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	DialogUpdate()
	DialogUpdate()
	DialogUpdate()
	DialogUpdate()
	DialogUpdate()
end