require "Frisk Character"
Arena.ResizeImmediate(565, 130)
FriskDirection = "R"
AlowFriskMovement(false, false)
Player.sprite.alpha = 0

if Encounter["phase"] > 1 and Encounter["NotUsedItems"] and string.sub(GetAlMightyGlobal("Archivimentazo"), 12, 12) == "0" then
	SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 11).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 13))
	Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 12}
elseif Encounter["phase"] == 1 and Encounter["NOHIT"] and string.sub(GetAlMightyGlobal("Archivimentazo"), 16, 16) == "0" then
	SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 15).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 17))
	Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 16}
end
timezone = string.gsub(package.loaded.os.date("%Z"), ":00", "")
timezone = string.gsub(timezone, ":30", "")
hour = tonumber(package.loaded.os.date("%H")) + tonumber(timezone)
while hour >= 24 do
	hour = hour - 24
end
while hour < 0 do
	hour = hour + 24
end
day = tonumber(package.loaded.os.date("%d"))
month = tonumber(package.loaded.os.date("%m"))

BlackDefinitive = CreateSprite("Bullets/Bones/Body","BelowBullet")
Corredor = CreateSprite("Overworld/Maps/Corredor","BelowBullet")
CorredorN = CreateSprite("Overworld/Maps/Corredor Noche","BelowBullet")
CorredorN.SetParent(Corredor)
PilarOw = CreateSprite("Overworld/Maps/PilarOW","BelowBullet")
PilarOwN = CreateSprite("Overworld/Maps/PilarOW Noche","BelowBullet")
PilarOw.SetParent(Corredor)
PilarOwN.SetParent(Corredor)
Pilares = {CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top"), CreateSprite("Overworld/Maps/Pilar","Top")}
Black = CreateSprite("Bullets/Bones/Body","Top")
Frisk.SetParent(Corredor)
for i=1,#Pilares do
	Pilares[i].SetParent(Corredor)
end
Black.color = {0,0,0}
BlackDefinitive.color = {0,0,0}
Black.Scale(640/5, 480)
BlackDefinitive.Scale(640/5, 480)
Frisk.MoveTo(221, -146)
Corredor.MoveTo(-100, 280)
Black.MoveTo(320, 240)
BlackDefinitive.MoveTo(320, 240)
PilarOw.MoveTo(100, 40)
PilarOwN.MoveTo(100, 40)
Pilares[1].SetVar("Datos", -935)
Pilares[2].SetVar("Datos", -475)
Pilares[3].SetVar("Datos", -15)
Pilares[4].SetVar("Datos", 465)
Pilares[5].SetVar("Datos", 945)
Pilares[6].SetVar("Datos", 1347)
Pilares[7].SetVar("Datos", 1587)
Pilares[8].SetVar("Datos", 1827)
Pilares[9].SetVar("Datos", 2287)
Corredor.alpha = 0.5 + 0.5*math.sin(math.rad(180/12*(hour - 8)))
CorredorN.alpha = 0.5 + 0.5*math.sin(math.rad(180/12*(hour - 20)))
PilarOw.alpha = Corredor.alpha
PilarOwN.alpha = CorredorN.alpha
for i=1,#Pilares do
	Pilares[i].color = {0.6 + 0.4*math.sin(math.rad(180/12*(hour - 8))), 0.6 + 0.4*math.sin(math.rad(180/12*(hour - 8))), 0.6 + 0.4*math.sin(math.rad(180/12*(hour - 8)))}
end

timer = 0
tableaux = 0

HuesosSuelo = {}

function Update()
	FraskoX = Frisk.x
	FriskUpdate()
	Black.SendToTop()
	if timer < 60 then
		timer = timer + 1
	elseif timer == 60 and Black.alpha > 0 then
		Black.alpha = Black.alpha - 0.04
		if Black.alpha <= 0 then
			timer = 61
		end
	elseif timer > 60 and timer <= 180 then
		timer = timer + 1
	elseif timer == 181 then
		Corredor.x = Corredor.x + 1
		if Corredor.x >= 98 then
			timer = 182
		end
	elseif timer > 181 and timer <= 300 then
		timer = timer + 1
	elseif timer == 301 then
		FriskAuto("Right")
		timer = 302
	elseif timer > 301 and timer <= 331 then
		timer = timer + 1
	elseif timer == 332 then
		Audio.PlaySound("suspenso")
		Black.alpha = 1
		timer = 333
	elseif timer > 332 and timer <= 512 then
		timer = timer + 1
	elseif timer == 513 then
		if Encounter["phase"] > 1 and Encounter["NOHIT"] and string.sub(GetAlMightyGlobal("Archivimentazo"), 17, 17) == "0" then
			SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 16).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 18))
			Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 17}
		end
		if Encounter["phase"] == 1 then
			Encounter["nextwaves"] = {"I promise..."}
		else
			Encounter["nextwaves"] = {"I still believe in you"}
		end
		for i=1,#Pilares do
			Pilares[i - tableaux].Remove()
			table.remove(Pilares, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		Black.Remove()
		PilarOw.Remove()
		PilarOwN.Remove()
		Frisk.Remove()
		Corredor.Remove()
		CorredorN.Remove()
		BlackDefinitive.Remove()
		State("DEFENDING")
	end
	if timer >= 301 and timer < 333 then
		if Frisk.absx > 321 and Corredor.x > -760 then
			Corredor.x = Corredor.x - 3
		elseif Frisk.absx < 319 and Corredor.x < 1400 then
			Corredor.x = Corredor.x + 3
		end
	end
	for i=1,#Pilares do
		Pilares[i].x = Pilares[i].GetVar("Datos") + 1*(Corredor.x - 1400)
	end
end

function OnHit()
	
end