require "Frisk Character"
FriskDirection = "R"
AlowFriskMovement(false, false)
AnimationAutoFrisk("Right")
TipoFrisk = "N"
Player.sprite.alpha = 0
Audio["enemydust"] = "HappyDust"

timer = 0
tableaux = 0
spawntimer = {math.random(450), math.random(300)}

Frisk.MoveTo(-50, 100)
BlackD = CreateSprite("Pixel","BelowBullet")
BlackD.MoveTo(320, 240)
BlackD.Scale(640, 480)
BlackD.color = {0,0,0}
Map = CreateSprite("Overworld/Maps/Ruins","BelowBullet")
Map.MoveTo(680, 240)
Frisk.layer = "BelowBullet"
Black = CreateSprite("Pixel","Top")
Black.MoveTo(320, 240)
Black.Scale(640, 480)
Black.color = {0,0,0}
White = CreateSprite("Pixel","Top")
White.MoveTo(320, 240)
White.Scale(640, 480)
White.color = {0,0,0}
White.alpha = 0

Objects = {}
Objects3D = {}
Stars = {}
Pipes = {}
Gears = {}
Columns = {}
Home = {}

function Update()
	FriskUpdate()
	timer = timer + 1
	if contador then
		contador = contador + 1
	end
	if timer <= 1200 then
		Map.x = Map.x - 2
		if Map.x <= 640 then
			Map.x = Map.x + 40
		end
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		if spawntimer[1] <= 0 then
			spawntimer[1] = math.random(300, 450)
			table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Hojas","BelowBullet"), X = Map.x + 82, Y = 108})
			Frisk.SendToTop()
		end
		if spawntimer[2] <= 0 then
			spawntimer[2] = math.random(100, 220)
			if math.random(2) == 1 then
				table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Vines 1","BelowBullet"), X = Map.x + 22, Y = 250})
			else
				table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Vines 2","BelowBullet"), X = Map.x + 82, Y = 250})
			end
		end
	elseif timer > 2400 and timer <= 3600 then
		Map.x = Map.x - 2
		if Map.x <= 720 then
			Map.x = Map.x + 120
		end
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		if spawntimer[1] <= 0 then
			spawntimer[1] = math.random(400, 600)
			table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Palo","BelowBullet"), X = Map.x + 142, Y = 108})
			Frisk.SendToTop()
			for i=1,#Objects3D do
				Objects3D[i].Sprite.SendToTop()
			end
		end
		if spawntimer[2] <= 0 then
			spawntimer[2] = math.random(100, 300)
			table.insert(Objects3D, {Sprite = CreateSprite("Overworld/Objects/Arbol","BelowBullet"), X = 723, Y = 250})
		end
	elseif timer > 3600 and timer <= 4800 then
		Map.x = Map.x - 2
		if Map.x <= -200 then
			Map.x = Map.x + 80
		end
	elseif timer > 4800 and timer <= 6000 then
		Map.x = Map.x - 2
		if Map.x <= 680 then
			Map.x = Map.x + 40
		end
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		if spawntimer[1] <= 0 then
			if math.random(6) == 1 then
				local positions = {0, 0, 0}
				for i=1,math.random(2) do
					repeat
						local done = true
						positions[i] = math.random(4)
						for j=1,3 do
							if positions[i] == positions[j] and i ~= j then
								done = false
							end
						end
					until done
					local spruait = CreateSprite("Overworld/Objects/Echo Flower/1","BelowBullet")
					spruait.SetPivot(0.5, 0)
					if math.random(2) == 1 then
						spruait.SetAnimation({"Overworld/Objects/Echo Flower/1","Overworld/Objects/Echo Flower/2"}, 0.3)
					else
						spruait.SetAnimation({"Overworld/Objects/Echo Flower/2","Overworld/Objects/Echo Flower/1"}, 0.3)
					end
					table.insert(Objects, {Sprite = spruait, X = Map.x - 22, Y = 270 + 40*positions[i]})
				end
				for i=1,4 do
					for j=1,#Objects do
						if Objects[j].Y == 470 - 40*i then
							Objects[j].Sprite.SendToTop()
						end
					end
				end
				for i=1,#Stars do
					Stars[i].Sprite.SendToTop()
				end
			end
			spawntimer[1] = 20
		end
		if spawntimer[2] <= 0 then
			local spruait = CreateSprite("Overworld/Objects/Star/1","BelowBullet")
			spruait.SetAnimation({"Overworld/Objects/Star/1","Overworld/Objects/Star/2","Overworld/Objects/Star/3","Overworld/Objects/Star/2"}, 0.1)
			local initalY = math.random(-200, 200)
			local moveY = math.min(math.max(initalY + math.random(-200, 200), -230), 230) - initalY
			table.insert(Stars, {Sprite = spruait, X = 650, Y = initalY, Move = {X = math.random(-200, 200), Y = moveY, Timer = 0}})
			spawntimer[2] = math.random(60, 150)
		end
	elseif timer > 6000 and timer <= 7200 then
		Map.x = Map.x - 2
		if Map.x <= -80 then
			Map.x = Map.x + 120
		end
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		spawntimer[3] = spawntimer[3] - 1
		if spawntimer[1] <= 0 then
			table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Estalagmita","BelowBullet"), X = Map.x + 762, Y = 520 - 40*math.random(6)})
			Frisk.SendToTop()
			spawntimer[1] = math.random(60, 100)
		end
		if spawntimer[2] <= 0 then
			if math.random(2) == 1 then
				table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Piedra","BelowBullet"), X = Map.x + 762, Y = 20*math.random(2)})
			end
			spawntimer[2] = 60
		end
		if spawntimer[3] <= 0 then
			table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Pilar","BelowBullet"), X = Map.x + 824, Y = 62})
			Frisk.SendToTop()
			spawntimer[3] = math.random(200, 400)
		end
	elseif timer > 7200 and timer <= 8400 then
		Map.x = Map.x - 2
		if Map.x <= 620 then
			Map.x = Map.x + 40
		end
		spawntimer[1] = spawntimer[1] - 1
		if spawntimer[1] <= 0 then
			table.insert(Pipes, {Sprites = {Body = CreateSprite("Overworld/Objects/Fire Pipe/Body","BelowBullet"), Head = CreateSprite("Overworld/Objects/Fire Pipe/Head","BelowBullet"), Flame = CreateSprite("Overworld/Objects/Fire Pipe/Fire","BelowBullet")}, X = Map.x + 42, Y = 180})
			spawntimer[1] = 100
		end
	elseif timer > 8400 and timer <= 9600 then
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		if spawntimer[1] <= 0 then
			if math.random(2) == 1 then
				table.insert(Gears, {Sprite = CreateSprite("Overworld/Objects/Gear","BelowBullet"), X = 690, Y = 200 + 40*math.random(4)})
			else
				table.insert(Gears, {Sprite = CreateSprite("Overworld/Objects/Small Gear","BelowBullet"), X = 690, Y = 200 + 40*math.random(4)})
			end
			spawntimer[1] = math.random(60, 100)
		end
		if spawntimer[2] <= 0 then
			table.insert(Columns, {Sprites = {CreateSprite("Overworld/Objects/Thing 1","BelowBullet"),CreateSprite("Overworld/Objects/Thing 1","BelowBullet"),CreateSprite("Overworld/Objects/Thing 1","BelowBullet"),CreateSprite("Overworld/Objects/Thing 2","BelowBullet")}, X = 780, Y = 170})
			spawntimer[2] = 240
		end
	elseif timer > 9600 and timer <= 10800 then
		Map.x = Map.x - 2
		if Map.x <= 760 then
			Map.x = Map.x + 160
		end
		spawntimer[1] = spawntimer[1] - 1
		if spawntimer[1] <= 0 then
			if math.random(2) == 1 then
				table.insert(Objects, {Sprite = CreateSprite("Overworld/Objects/Jarros","BelowBullet"), X = Map.x - 100, Y = 228})
			end
			spawntimer[1] = 20
		end
	elseif timer > 10800 and timer <= 12000 then
		Map.x = Map.x - 2
		if Map.x <= -280 then
			Map.x = Map.x + 400
		end
	elseif timer > 13200 and timer <= 14400 then
		spawntimer[1] = spawntimer[1] - 1
		spawntimer[2] = spawntimer[2] - 1
		spawntimer[3] = spawntimer[3] - 1
		spawntimer[4] = spawntimer[4] - 1
		spawntimer[5] = spawntimer[5] - 1
		spawntimer[6] = spawntimer[6] - 1
		if spawntimer[1] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/2","BelowBullet"), X = 867, Y = 285, Vel = 1})
			spawntimer[1] = 640
		end
		if spawntimer[2] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/3","BelowBullet"), X = 867, Y = 259, Vel = 0.75})
			spawntimer[2] = 830
		end
		if spawntimer[3] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/4","BelowBullet"), X = 903, Y = 223, Vel = 1.25})
			spawntimer[3] = 549
		end
		if spawntimer[4] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/5","BelowBullet"), X = 858, Y = 229, Vel = 1.5})
			spawntimer[4] = 494
		end
		if spawntimer[5] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/6","BelowBullet"), X = 949, Y = 273, Vel = 2})
			spawntimer[5] = 320
		end
		if spawntimer[6] <= 0 then
			table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/7","BelowBullet"), X = 690, Y = 210, Vel = 1.75})
			spawntimer[6] = 365
		end
		for i=1,6 do
			for j=1,#Home do
				if Home[j].Vel == 0.5 + 0.25*i then
					Home[j].Sprite.SendToTop()
				end
			end
		end
		Frisk.SendToTop()
	elseif timer > 14400 and timer <= 15600 then
		Map.x = Map.x - 2
		if Map.x <= 440 then
			Map.x = Map.x + 240
		end
		spawntimer[1] = spawntimer[1] - 1
		if spawntimer[1] <= 0 then
			table.insert(Objects3D, {Sprite = CreateSprite("Overworld/Maps/Pilar","BelowBullet"), X = 707, Y = 240})
			spawntimer[1] = 160
		end
	end
	if timer <= 120 then
		if timer == 1 then
			NewAudio.PlaySound("One", "Megalo Strike Back Lullaby", false, 0)
		end
		Black.alpha = 1/120*(120 - timer)
		NewAudio.SetVolume("One", 1/120*timer)
	elseif timer > 120 and timer <= 420 then
		Frisk.x = -50 + 370/300*(timer - 120)
	elseif timer == 421 then
		FriskFrameVel = 16
	elseif timer == 1200 then
		Map.x = -40
		for i=1,#Objects do
			local Datos = Objects[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
	elseif timer == 2400 then
		Map.Set("Overworld/Maps/Snowdin")
		Map.x = 840
		spawntimer = {0, math.random(600)}
	elseif timer == 3600 then
		Storm = CreateSprite("Overworld/Objects/Storm","BelowBullet")
		Storm.MoveTo(400, 320)
		Storm.alpha = 0
		Map.x = -120
		for i=1,#Objects do
			local Datos = Objects[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		for i=1,#Objects3D do
			local Datos = Objects3D[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects3D, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
	elseif timer > 3600 and timer <= 4200 then
		Storm.alpha = 0.5/600*(timer - 3600)
	elseif timer == 4800 then
		Storm.Remove()
		Storm = nil
		Map.Set("Overworld/Maps/Waterfall")
		Map.x = 720
		spawntimer = {0, math.random(150)}
	elseif timer == 6000 then
		Map.x = 40
		for i=1,#Objects do
			local Datos = Objects[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		for i=1,#Stars do
			local Datos = Stars[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Stars, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		spawntimer = {math.random(300), 0, math.random(100)}
	elseif timer == 7200 then
		CORE = CreateSprite("Overworld/Objects/THE CORE","BelowBullet")
		CORE.MoveTo(875, 324)
		Map.Set("Overworld/Maps/Hotland")
		Map.x = 660
		for i=1,#Objects do
			local Datos = Objects[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		contador = 0
		spawntimer = {0}
	elseif timer > 7200 and timer < 8400 then
		CORE.MoveTo(875 - 1110/1200*(timer - 7200), 324)
	elseif timer == 8400 then
		CORE.Remove()
		CORE = nil
		Energy = CreateSprite("Overworld/Objects/Energy","BelowBullet")
		Energy.MoveTo(340, 28)
		Map.x = -20
		for i=1,#Pipes do
			local Datos = Pipes[i - tableaux]
			Datos.Sprites.Body.Remove()
			Datos.Sprites.Head.Remove()
			Datos.Sprites.Flame.Remove()
			table.remove(Pipes, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		contador = nil
		spawntimer = {math.random(100), 0}
	elseif timer == 9600 then
		Energy.Remove()
		Energy = nil
		Map.Set("Overworld/Maps/CORE")
		Map.x = 920
		for i=1,#Gears do
			local Datos = Gears[i - tableaux]
			Datos.Sprite.Remove()
			if Datos.Circles then
				for j=1,#Datos.Circles do
					Datos.Circles[j].Remove()
				end
			end
			table.remove(Gears, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		for i=1,#Columns do
			local Datos = Columns[i - tableaux]
			for j=1,#Datos.Sprites do
				Datos.Sprites[j].Remove()
			end
			table.remove(Columns, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		spawntimer = {0}
	elseif timer == 10800 then
		Efecto = CreateSprite("Overworld/Objects/Core's heat","BelowBullet")
		Efecto.MoveTo(Map.x + 400, 240)
		Map.x = 120
		for i=1,#Objects do
			local Datos = Objects[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
	elseif timer == 12000 then
		Efecto.Remove()
		Efecto = nil
		Map.Set("Overworld/Maps/New Home")
		Map.x = 640
	elseif timer == 13200 then
		BG = CreateSprite("Overworld/Objects/New Home BG/1","BelowBullet")
		BG.MoveTo(640, 308)
		Map.x = 0
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/2","BelowBullet"), X = 248, Y = 285, Vel = 1})
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/3","BelowBullet"), X = 215.25, Y = 259, Vel = 0.75})
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/4","BelowBullet"), X = 218, Y = 223, Vel = 1.25})
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/5","BelowBullet"), X = 118.5, Y = 229, Vel = 1.5})
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/6","BelowBullet"), X = 311, Y = 273, Vel = 2})
		table.insert(Home, {Sprite = CreateSprite("Overworld/Objects/New Home BG/7","BelowBullet"), X = 53, Y = 210, Vel = 1.75})
		for i=1,6 do
			for j=1,#Home do
				if Home[j].Vel == 0.5 + 0.25*i then
					Home[j].Sprite.SendToTop()
				end
			end
		end
		spawntimer = {0,0,0,0,0,0}
	elseif timer == 14400 then
		BG.Remove()
		BG = nil
		Map.Set("Overworld/Maps/Corredor")
		Map.x = 680
		TipoFrisk = "SN"
		for i=1,#Home do
			local Datos = Home[i - tableaux]
			Datos.Sprite.Remove()
			table.remove(Home, i - tableaux)
			tableaux = tableaux + 1
		end
		tableaux = 0
		spawntimer = {0}
	end
	if timer > 1100 and timer <= 1220 then
		White.alpha = math.sin(math.rad(180/120*(timer - 1100)))
		if timer == 1160 then
			Froggit = CreateSprite("Flashbacks/Froggit 1","Top")
			Froggit.MoveTo(220, 294)
			Vegetoid = CreateSprite("Flashbacks/Vegetoid 1","Top")
			Vegetoid.MoveTo(420, 292)
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 1210 then
			Audio.PlaySound("HappySlice")
			Slice = CreateSprite("UI/Battle/spr_slice_o_1", "Top")
			Slice.MoveTo(220, 300)
			White.SendToTop()
		elseif timer == 1216 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 1222 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 1228 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 1234 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 1240 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Froggit.Set("Flashbacks/Froggit 2")
	elseif timer > 1240 and timer <= 1280 then
		Froggit.x = 220 + (30 - 7.5*(timer - 1240)/10)*math.sin(math.rad(360/10*(timer - 1240)))
		if timer == 1250 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(420, 300)
		elseif timer == 1256 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 1262 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 1268 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 1274 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 1280 then
			Slice.alpha = 0
			for i=1,3 do
				Audio.PlaySound("HappyDamage")
			end
			Vegetoid.Set("Flashbacks/Vegetoid 2")
		end
	elseif timer > 1280 and timer <= 1320 then
		Vegetoid.x = 420 + (30 - 7.5*(timer - 1280)/10)*math.sin(math.rad(360/10*(timer - 1280)))
		if timer == 1281 then
			Froggit.Dust(true)
			Froggit = nil
		end
	elseif timer == 1321 then
		Vegetoid.Dust(true)
		Vegetoid = nil
	elseif timer > 1340 and timer <= 1460 then
		White.alpha = math.sin(math.rad(180/120*(timer - 1340)))
		if timer == 1400 then
			Black.alpha = 0
		end
	elseif timer > 2300 and timer <= 2420 then
		White.alpha = math.sin(math.rad(180/120*(timer - 2300)))
		if timer == 2360 then
			Toriel = CreateSprite("Flashbacks/Toriel 1","Top")
			Toriel.MoveTo(320, 341)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 2410 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 340)
		elseif timer == 2416 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 2422 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 2428 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 2434 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 2440 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Toriel.Set("Flashbacks/Toriel 2")
	elseif timer > 2440 and timer <= 2480 then
		Toriel.x = 320 + (30 - 7.5*(timer - 2440)/10)*math.sin(math.rad(360/10*(timer - 2440)))
	elseif timer == 2540 then
		Toriel.Set("Flashbacks/Toriel 3")
	elseif timer == 2570 then
		Toriel.Dust(true)
		Toriel = nil
	elseif timer > 2590 and timer <= 2710 then
		White.alpha = math.sin(math.rad(180/120*(timer - 2590)))
		if timer == 2650 then
			Black.alpha = 0
		end
	elseif timer > 3500 and timer <= 3620 then
		White.alpha = math.sin(math.rad(180/120*(timer - 3500)))
		if timer == 3560 then
			Dogamy = CreateSprite("Flashbacks/Dogamy 1","Top")
			Dogamy.MoveTo(229, 336)
			Dogaressa = CreateSprite("Flashbacks/Dogaressa 1","Top")
			Dogaressa.MoveTo(411, 332)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 3610 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(200, 340)
		elseif timer == 3616 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 3622 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 3628 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 3634 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 3640 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Dogamy.Set("Flashbacks/Dogamy 2")
	elseif timer > 3640 and timer <= 3680 then
		Dogamy.x = 229 + (30 - 7.5*(timer - 3640)/10)*math.sin(math.rad(360/10*(timer - 3640)))
		if timer == 3650 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(440, 340)
		elseif timer == 3656 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 3662 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 3668 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 3674 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 3680 then
			Slice.alpha = 0
			for i=1,3 do
				Audio.PlaySound("HappyDamage")
			end
			Dogaressa.Set("Flashbacks/Dogaressa 2")
		end
	elseif timer > 3680 and timer <= 3720 then
		Dogaressa.x = 411 + (30 - 7.5*(timer - 3680)/10)*math.sin(math.rad(360/10*(timer - 3680)))
		if timer == 3681 then
			Dogamy.Dust(true)
			Dogamy = nil
		end
	elseif timer == 3721 then
		Dogaressa.Dust(true)
		Dogaressa = nil
	elseif timer > 3740 and timer <= 3860 then
		White.alpha = math.sin(math.rad(180/120*(timer - 3740)))
		if timer == 3800 then
			Black.alpha = 0
		end
	elseif timer > 4700 and timer <= 4820 then
		White.alpha = math.sin(math.rad(180/120*(timer - 4700)))
		if timer == 4760 then
			Sans = CreateSprite("Flashbacks/Sans 1","Top")
			Sans.MoveTo(320, 312)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 4810 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 320)
		elseif timer == 4816 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
		if timer > 4810 then
			Sans.x = 320 + 100*math.sin(math.rad(90/15*(timer - 4810)))
		end
	elseif timer > 4820 and timer <= 4825 then
		Sans.x = 320 + 100*math.sin(math.rad(90/15*(timer - 4810)))
		if timer == 4822 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		end
	elseif timer == 4828 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 4834 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 4840 then
		Slice.alpha = 0
	elseif timer >= 4850 and timer <= 4865 then
		Sans.x = 420 - 100*math.sin(math.rad(90/15*(timer - 4850)))
		if timer == 4850 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(420, 320)
			Sans.Set("Flashbacks/Sans 2")
		elseif timer == 4856 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 4862 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		end
	elseif timer == 4868 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 4874 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 4880 then
		Slice.alpha = 0
	elseif timer >= 4890 and timer <= 4905 then
		Sans.x = 320 - 100*math.sin(math.rad(90/15*(timer - 4890)))
		if timer == 4890 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 320)
			Sans.Set("Flashbacks/Sans 3")
		elseif timer == 4896 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 4902 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		end
	elseif timer == 4908 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 4914 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 4920 then
		Slice.alpha = 0
	elseif timer >= 4930 and timer <= 4945 then
		Sans.x = 220 + 100*math.sin(math.rad(90/15*(timer - 4930)))
		if timer == 4930 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(220, 320)
			Sans.Set("Flashbacks/Sans 4")
		elseif timer == 4936 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 4942 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		end
	elseif timer == 4948 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 4954 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 4960 then
		Slice.alpha = 0
	elseif timer >= 4970 and timer <= 4985 then
		Sans.x = 320 + 100*math.sin(math.rad(90/15*(timer - 4970)))
		if timer == 4970 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(420, 320)
		elseif timer == 4976 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 4982 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		end
	elseif timer == 4986 then
		Sans.Set("Flashbacks/Sans 5")
	elseif timer == 4988 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 4994 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 5000 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Sans.Set("Flashbacks/Sans 6")
	elseif timer > 5000 and timer <= 5040 then
		Sans.x = 420 + (30 - 7.5*(timer - 5000)/10)*math.sin(math.rad(360/10*(timer - 5000)))
	elseif timer == 5070 then
		Sans.Dust(true)
		Sans = nil
	elseif timer > 5090 and timer <= 5210 then
		White.alpha = math.sin(math.rad(180/120*(timer - 5090)))
		if timer == 5150 then
			Black.alpha = 0
		end
	elseif timer > 5900 and timer <= 6020 then
		White.alpha = math.sin(math.rad(180/120*(timer - 5900)))
		if timer == 5960 then
			Aaron = CreateSprite("Flashbacks/Aaron 1","Top")
			Aaron.MoveTo(220, 338)
			Temmie = CreateSprite("Flashbacks/Temmie 1","Top")
			Temmie.MoveTo(420, 288)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 6010 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(220, 340)
		elseif timer == 6016 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 6022 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 6028 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 6034 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 6040 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Aaron.Set("Flashbacks/Aaron 2")
	elseif timer > 6040 and timer <= 6080 then
		Aaron.x = 220 + (30 - 7.5*(timer - 6040)/10)*math.sin(math.rad(360/10*(timer - 6040)))
		if timer == 6050 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(420, 290)
		elseif timer == 6056 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 6062 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 6068 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 6074 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 6080 then
			Slice.alpha = 0
			for i=1,3 do
				Audio.PlaySound("HappyDamage")
			end
			Temmie.Set("Flashbacks/Temmie 2")
		end
	elseif timer > 6080 and timer <= 6120 then
		Temmie.x = 420 + (30 - 7.5*(timer - 6080)/10)*math.sin(math.rad(360/10*(timer - 6080)))
		if timer == 6081 then
			Aaron.Dust(true)
			Aaron = nil
		end
	elseif timer == 6121 then
		Temmie.Dust(true)
		Temmie = nil
	elseif timer > 6140 and timer <= 6260 then
		White.alpha = math.sin(math.rad(180/120*(timer - 6140)))
		if timer == 6200 then
			Black.alpha = 0
		end
	elseif timer > 7100 and timer <= 7220 then
		White.alpha = math.sin(math.rad(180/120*(timer - 7100)))
		if timer == 7160 then
			Undyne = CreateSprite("Flashbacks/Undyne 1","Top")
			Undyne.MoveTo(310, 357)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 7210 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 350)
		elseif timer == 7216 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 7222 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 7228 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 7234 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 7240 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
	elseif timer > 7240 and timer <= 7280 then
		Undyne.x = 310 + (30 - 7.5*(timer - 7240)/10)*math.sin(math.rad(360/10*(timer - 7240)))
		if timer == 7260 then
			Undyne.Set("Flashbacks/Undyne 2")
		end
	elseif timer == 7290 then
		Audio.PlaySound("HappySlice")
		Slice.alpha = 1
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(320, 350)
	elseif timer == 7296 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 7302 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 7308 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 7314 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 7320 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
	elseif timer > 7320 and timer <= 7360 then
		Undyne.x = 310 + (30 - 7.5*(timer - 7320)/10)*math.sin(math.rad(360/10*(timer - 7320)))
		if timer == 7340 then
			Undyne.Set("Flashbacks/Undyne 3")
		end
	elseif timer == 7370 then
		Audio.PlaySound("HappySlice")
		Slice.alpha = 1
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(320, 350)
	elseif timer == 7376 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 7382 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 7388 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 7394 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 7400 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
	elseif timer > 7400 and timer <= 7440 then
		Undyne.x = 310 + (30 - 7.5*(timer - 7400)/10)*math.sin(math.rad(360/10*(timer - 7400)))
	elseif timer == 7470 then
		Undyne.Dust(true)
		Undyne = nil
	elseif timer > 7490 and timer <= 7610 then
		White.alpha = math.sin(math.rad(180/120*(timer - 7490)))
		if timer == 7550 then
			Black.alpha = 0
		end
	elseif timer > 8300 and timer <= 8420 then
		White.alpha = math.sin(math.rad(180/120*(timer - 5900)))
		if timer == 8360 then
			Guard1 = CreateSprite("Flashbacks/Guard 1","Top")
			Guard1.MoveTo(200, 338.5)
			Guard2 = CreateSprite("Flashbacks/Guard 2","Top")
			Guard2.MoveTo(440, 343)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 8410 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(190, 340)
		elseif timer == 8416 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 8422 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 8428 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 8434 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 8440 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
	elseif timer > 8440 and timer <= 8480 then
		Guard1.x = 200 + (30 - 7.5*(timer - 8440)/10)*math.sin(math.rad(360/10*(timer - 8440)))
		if timer == 8450 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(430, 340)
		elseif timer == 8456 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 8462 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 8468 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 8474 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 8480 then
			Slice.alpha = 0
			for i=1,3 do
				Audio.PlaySound("HappyDamage")
			end
		end
	elseif timer > 8480 and timer <= 8520 then
		Guard2.x = 440 + (30 - 7.5*(timer - 8480)/10)*math.sin(math.rad(360/10*(timer - 8480)))
		if timer == 8481 then
			Guard1.Dust(true)
			Guard1 = nil
		end
	elseif timer == 8521 then
		Guard2.Dust(true)
		Guard2 = nil
	elseif timer > 8540 and timer <= 8660 then
		White.alpha = math.sin(math.rad(180/120*(timer - 8540)))
		if timer == 8600 then
			Black.alpha = 0
		end
	elseif timer > 9500 and timer <= 9620 then
		White.alpha = math.sin(math.rad(180/120*(timer - 9500)))
		if timer == 9560 then
			Muffet = CreateSprite("Flashbacks/Muffet 1","Top")
			Muffet.MoveTo(320, 342)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 9610 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 340)
		elseif timer == 9616 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 9622 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 9628 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 9634 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 9640 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Muffet.Set("Flashbacks/Muffet 2")
	elseif timer > 9640 and timer <= 9680 then
		Muffet.x = 320 + (30 - 7.5*(timer - 9640)/10)*math.sin(math.rad(360/10*(timer - 9640)))
	elseif timer == 9681 then
		Muffet.Dust(true)
		Muffet = nil
	elseif timer > 9700 and timer <= 9820 then
		White.alpha = math.sin(math.rad(180/120*(timer - 9700)))
		if timer == 9760 then
			Black.alpha = 0
		end
	elseif timer > 10700 and timer <= 10820 then
		White.alpha = math.sin(math.rad(180/120*(timer - 10700)))
		if timer == 10760 then
			Knight = CreateSprite("Flashbacks/Knight 1","Top")
			Knight.MoveTo(220, 340)
			Madjick = CreateSprite("Flashbacks/Madjick 1","Top")
			Madjick.MoveTo(420, 360)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 10810 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(230, 340)
		elseif timer == 10816 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 10822 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 10828 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 10834 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 10840 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Knight.Set("Flashbacks/Knight 2")
	elseif timer > 10840 and timer <= 10880 then
		Knight.x = 220 + (30 - 7.5*(timer - 10840)/10)*math.sin(math.rad(360/10*(timer - 10840)))
		if timer == 10850 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(420, 360)
		elseif timer == 10856 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 10862 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 10868 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 10874 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 10880 then
			Slice.alpha = 0
			for i=1,3 do
				Audio.PlaySound("HappyDamage")
			end
			Madjick.Set("Flashbacks/Madjick 2")
		end
	elseif timer > 10880 and timer <= 10920 then
		Madjick.x = 420 + (30 - 7.5*(timer - 10880)/10)*math.sin(math.rad(360/10*(timer - 10880)))
		if timer == 10881 then
			Knight.Dust(true)
			Knight = nil
		end
	elseif timer == 10921 then
		Madjick.Dust(true)
		Madjick = nil
	elseif timer > 10940 and timer <= 11060 then
		White.alpha = math.sin(math.rad(180/120*(timer - 10940)))
		if timer == 11000 then
			Black.alpha = 0
		end
	elseif timer > 11900 and timer <= 12020 then
		White.alpha = math.sin(math.rad(180/120*(timer - 11900)))
		if timer == 11960 then
			Mettaton = CreateSprite("Flashbacks/Mettaton 1","Top")
			Mettaton.MoveTo(320, 355)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 12010 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 360)
		elseif timer == 12016 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 12022 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 12028 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 12034 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 12040 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Mettaton.Set("Flashbacks/Mettaton 2")
	elseif timer > 12040 and timer <= 12080 then
		Mettaton.x = 320 + (30 - 7.5*(timer - 12040)/10)*math.sin(math.rad(360/10*(timer - 12040)))
	elseif timer == 12081 then
		Audio.PlaySound("HappyExplotion")
		White.color = {1,1,1}
	elseif timer > 12081 and timer <= 12096 then
		White.alpha = math.sin(math.rad(90/15*(timer - 12081)))
	elseif timer == 12160 then
		Audio.PlaySound("HappyDust")
		Mettaton.Remove()
		Mettaton = nil
	elseif timer > 12160 and timer <= 12220 then
		White.alpha = math.cos(math.rad(90/60*(timer - 12160)))
	elseif timer > 12220 and timer <= 12280 then
		Black.alpha = math.cos(math.rad(90/60*(timer - 12220)))
		if timer == 12280 then
			White.color = {0,0,0}
		end
	elseif timer > 13100 and timer <= 13220 then
		White.alpha = math.sin(math.rad(180/120*(timer - 13100)))
		if timer == 13160 then
			Papyrus = CreateSprite("Flashbacks/Papyrus 1","Top")
			Papyrus.MoveTo(320, 271)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 13210 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 270)
		elseif timer == 13216 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 13222 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 13228 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 13234 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 13240 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Papyrus.Set("Flashbacks/Papyrus 2")
	elseif timer > 13240 and timer <= 13280 then
		Papyrus.x = 320 + (30 - 7.5*(timer - 13240)/10)*math.sin(math.rad(360/10*(timer - 13240)))
	elseif timer == 13281 then
		Audio.PlaySound("HappySlice")
		Slice.alpha = 1
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(320, 270)
	elseif timer == 13287 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 13293 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 13299 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 13305 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 13311 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Papyrus.Set("Flashbacks/Papyrus 3")
	elseif timer > 13311 and timer <= 13351 then
		Papyrus.x = 320 + (30 - 7.5*(timer - 13311)/10)*math.sin(math.rad(360/10*(timer - 13311)))
	elseif timer == 13352 then
		Audio.PlaySound("HappySlice")
		Slice.alpha = 1
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(320, 270)
	elseif timer == 13358 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 13364 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 13370 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 13376 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 13382 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Papyrus.Set("Flashbacks/Papyrus 4")
	elseif timer > 13382 and timer <= 13422 then
		Papyrus.x = 320 + (30 - 7.5*(timer - 13382)/10)*math.sin(math.rad(360/10*(timer - 13382)))
	elseif timer == 13423 then
		Audio.PlaySound("HappySlice")
		Slice.alpha = 1
		Slice.Set("UI/Battle/spr_slice_o_1")
		Slice.MoveTo(320, 270)
	elseif timer == 13429 then
		Slice.Set("UI/Battle/spr_slice_o_2")
	elseif timer == 13435 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 13441 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 13447 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 13453 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Papyrus.Dust(true)
		Papyrus = nil
	elseif timer > 13473 and timer <= 13593 then
		White.alpha = math.sin(math.rad(180/120*(timer - 13473)))
		if timer == 13533 then
			Black.alpha = 0
		end
	elseif timer > 14300 and timer <= 14420 then
		White.alpha = math.sin(math.rad(180/120*(timer - 14300)))
		if timer == 14360 then
			Asgore = CreateSprite("Flashbacks/Asgore 1","Top")
			Asgore.MoveTo(320, 338)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		elseif timer == 14410 then
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 340)
		elseif timer == 14416 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		end
	elseif timer == 14422 then
		Slice.Set("UI/Battle/spr_slice_o_3")
	elseif timer == 14428 then
		Slice.Set("UI/Battle/spr_slice_o_4")
	elseif timer == 14434 then
		Slice.Set("UI/Battle/spr_slice_o_5")
	elseif timer == 14440 then
		Slice.alpha = 0
		for i=1,3 do
			Audio.PlaySound("HappyDamage")
		end
		Asgore.Set("Flashbacks/Asgore 2")
	elseif timer > 14440 and timer <= 14480 then
		Asgore.x = 320 + (30 - 7.5*(timer - 14440)/10)*math.sin(math.rad(360/10*(timer - 14440)))
	elseif timer == 14481 then
		Asgore.Dust(true)
		Asgore = nil
	elseif timer > 14501 and timer <= 14621 then
		White.alpha = math.sin(math.rad(180/120*(timer - 14501)))
		if timer == 14561 then
			Black.alpha = 0
		end
	elseif timer > 15500 and timer <= 15620 then
		White.alpha = math.sin(math.rad(180/120*(timer - 15500)))
		if timer == 15560 then
			Flowey = CreateSprite("Flashbacks/Flowey 1","Top")
			Flowey.MoveTo(320, 284)
			Slice.SendToTop()
			White.SendToTop()
			Black.alpha = 1
		end
	elseif timer >= 15680 and timer <= 15710 then
		White.color = {1,1,1}
		White.alpha = math.sin(math.rad(90/30*(timer - 15680)))
		if timer == 15680 then
			Flowey.Set("Flashbacks/Flowey 2")
			Audio.PlaySound("HappySlice")
			Slice.alpha = 1
			Slice.Set("UI/Battle/spr_slice_o_1")
			Slice.MoveTo(320, 290)
		elseif timer == 15686 then
			Slice.Set("UI/Battle/spr_slice_o_2")
		elseif timer == 15692 then
			Slice.Set("UI/Battle/spr_slice_o_3")
		elseif timer == 15698 then
			Slice.Set("UI/Battle/spr_slice_o_4")
		elseif timer == 15704 then
			Slice.Set("UI/Battle/spr_slice_o_5")
		elseif timer == 15710 then
			Flowey.Remove()
			Flowey = nil
			Slice.Remove()
			Slice = nil
		end
	elseif timer > 15740 and timer <= 15860 then
		White.alpha = math.cos(math.rad(90/120*(timer - 15740)))
	end
	if Energy then
		Energy.x = Energy.x - 1
		if Energy.x <= 300 then
			Energy.x = Energy.x + 40
		end
	end
	if BG then
		BG.x = BG.x - 0.25
		if BG.x <= 0 then
			BG.x = BG.x + 640
		end
	end
	if Efecto then
		Efecto.MoveTo(Map.x + 400, 240)
		Efecto.alpha = 0.15 - 0.15*math.cos(math.rad(360/120*(timer - 10800)))
	end
	if Storm then
		Storm.x = Storm.x - 1
		Storm.y = Storm.y - 1
		if Storm.x <= 240 then
			Storm.x = Storm.x + 160
		end
		if Storm.y <= 160 then
			Storm.y = Storm.y + 160
		end
	end
	for i=1,#Objects do
		local Datos = Objects[i - tableaux]
		Datos.X = Datos.X - 2
		Datos.Sprite.MoveTo(Datos.X, Datos.Y)
		if Datos.X <= -100 then
			Datos.Sprite.Remove()
			table.remove(Objects, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Objects3D do
		local Datos = Objects3D[i - tableaux]
		Datos.X = Datos.X - 3
		Datos.Sprite.MoveTo(Datos.X, Datos.Y)
		if Datos.X <= -100 then
			Datos.Sprite.Remove()
			table.remove(Objects3D, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Stars do
		local Datos = Stars[i - tableaux]
		Datos.X = Datos.X - 2
		Datos.Move.Timer = Datos.Move.Timer + 1
		Datos.Sprite.MoveTo(Datos.X + Datos.Move.X/2 - Datos.Move.X/2*math.cos(math.rad(180/150*Datos.Move.Timer)), 260 + Datos.Y + Datos.Move.Y/2 - Datos.Move.Y/2*math.cos(math.rad(180/150*Datos.Move.Timer)))
		if Datos.Move.Timer >= 150 then
			Datos.X = Datos.X + Datos.Move.X
			Datos.Y = Datos.Y + Datos.Move.Y
			Datos.Move.X = math.random(-200, 200)
			Datos.Move.Y = math.min(math.max(Datos.Y + math.random(-200, 200), -230), 230) - Datos.Y
			Datos.Move.Timer = 0
		end
		if Datos.X <= -200 then
			Datos.Sprite.Remove()
			table.remove(Stars, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Pipes do
		local Datos = Pipes[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		Datos.Timer = Datos.Timer + 1
		Datos.X = Datos.X - 2
		Datos.Sprites.Body.MoveTo(Datos.X, Datos.Y + 17)
		if contador > 60 then
			if contador <= 70 then
				Datos.Sprites.Head.MoveTo(Datos.X + 1, Datos.Y + 53 - 4*math.sin(math.rad(90/10*(contador - 60))))
				Datos.Sprites.Flame.Scale(math.sin(math.rad(90/10*(contador - 60))), math.sin(math.rad(90/10*(contador - 60))))
				Datos.Sprites.Flame.alpha = math.sin(math.rad(90/10*(contador - 60)))
			elseif contador > 110 then
				Datos.Sprites.Head.MoveTo(Datos.X + 1, Datos.Y + 53 - 4*math.cos(math.rad(90/10*(contador - 110))))
				Datos.Sprites.Flame.Scale(math.cos(math.rad(90/10*(contador - 110))), math.cos(math.rad(90/10*(contador - 110))))
				Datos.Sprites.Flame.alpha = math.cos(math.rad(90/10*(contador - 110)))
			else
				Datos.Sprites.Head.MoveTo(Datos.X + 1, Datos.Y + 49)
				Datos.Sprites.Flame.Scale(1, (116 + 4*math.cos(math.rad(360/10*(contador - 70))))/120)
				Datos.Sprites.Flame.alpha = 1
			end
		else
			Datos.Sprites.Head.MoveTo(Datos.X + 1, Datos.Y + 53)
			Datos.Sprites.Flame.Scale(0, 0)
			Datos.Sprites.Flame.alpha = 0
		end
		Datos.Sprites.Flame.MoveTo(Datos.X + 1, Datos.Y + 56 + 60*Datos.Sprites.Flame.yscale)
		if Datos.X <= -20 then
			Datos.Sprites.Body.Remove()
			Datos.Sprites.Head.Remove()
			Datos.Sprites.Flame.Remove()
			table.remove(Pipes, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Gears do
		local Datos = Gears[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		if not Datos.Circles then
			Datos.Circles = {}
			for j=1,6 do
				local spruait = CreateSprite("Overworld/Objects/Circle","BelowBullet")
				spruait.Scale(Datos.Sprite.width/60, Datos.Sprite.width/60)
				table.insert(Datos.Circles, spruait)
			end
		end
		Datos.Timer = Datos.Timer + 1
		Datos.X = Datos.X - 2
		Datos.Sprite.MoveTo(Datos.X, Datos.Y)
		for j=1,#Datos.Circles do
			Datos.Circles[j].MoveTo(Datos.X - Datos.Sprite.width/2*math.cos(math.rad(90/40*(Datos.Timer) + 60*j)), Datos.Y + Datos.Sprite.width/2*math.sin(math.rad(90/40*(Datos.Timer) + 60*j)))
		end
		if Datos.X <= -60 then
			Datos.Sprite.Remove()
			for j=1,#Datos.Circles do
				Datos.Circles[j].Remove()
			end
			table.remove(Gears, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Columns do
		local Datos = Columns[i - tableaux]
		if not Datos.Timer then
			Datos.Timer = 0
		end
		Datos.Timer = Datos.Timer + 1
		Datos.X = Datos.X - 2
		for j=1,#Datos.Sprites do
			Datos.Sprites[j].MoveTo(Datos.X + 20*math.sin(math.rad(360/120*Datos.Timer - 45*j)), Datos.Y - 40 + 80*j)
			Datos.Sprites[j].alpha = 1 + math.cos(math.rad(360/120*Datos.Timer - 45*j))
		end
		local tableaux2 = 0
		for j=1,#Gears do
			local Datos2 = Gears[j - tableaux2]
			if Datos2.X >= Datos.X - 110 and Datos2.X <= Datos.X + 110 then
				Datos2.Sprite.Remove()
				if Datos2.Circles then
					for k=1,#Datos2.Circles do
						Datos2.Circles[k].Remove()
					end
				end
				table.remove(Gears, j - tableaux2)
				tableaux2 = tableaux2 + 1
			end
		end
		if Datos.X <= -60 then
			for j=1,#Datos.Sprites do
				Datos.Sprites[j].Remove()
			end
			table.remove(Columns, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	for i=1,#Home do
		local Datos = Home[i - tableaux]
		Datos.X = Datos.X - Datos.Vel
		Datos.Sprite.MoveTo(Datos.X, Datos.Y)
		if Datos.X <= -310 then
			Datos.Sprite.Remove()
			table.remove(Home, i - tableaux)
			tableaux = tableaux + 1
		end
	end
	tableaux = 0
	if contador and contador >= 120 then
		contador = 0
	end
	if White then
		White.SendToTop()
	end
	if timer == 500 then
		Text = CreateSprite("Menu/Disbelief","Top")
		Text.MoveTo(320, 370)
		Text.Scale(0.5, 0.5)
		Text.alpha = 0
	elseif timer > 500 and timer <= 560 then
		Text.alpha = 1/60*(timer - 500)
	elseif timer > 1000 and timer <= 1060 then
		Text.alpha = 1/60*(1060 - timer)
	elseif timer == 1061 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Made")
		Text.MoveTo(320, 400)
		Text.Scale(1, 1)
	elseif timer > 1600 and timer <= 1660 then
		Text.alpha = 1/60*(timer - 1600)
	elseif timer > 2200 and timer <= 2260 then
		Text.alpha = 1/60*(2260 - timer)
	elseif timer == 2261 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Based")
	elseif timer > 2800 and timer <= 2860 then
		Text.alpha = 1/60*(timer - 2800)
	elseif timer > 3400 and timer <= 3460 then
		Text.alpha = 1/60*(3460 - timer)
	elseif timer == 3461 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Papyrus")
		Text.MoveTo(320, 450)
		Text2 = CreateSprite("Credits/"..GetAlMightyGlobal("Idioma").."/Phase 1","Top")
		Text2.MoveTo(320, 300.5)
		Text2.alpha = 0
		Text3 = CreateSprite("Credits/Phase 1","Top")
		Text3.MoveTo(320, 375)
		Text3.alpha = 0
	elseif timer > 4000 and timer <= 4060 then
		Text.alpha = 1/60*(timer - 4000)
		Text2.alpha = 1/60*(timer - 4000)
		Text3.alpha = 1/60*(timer - 4000)
	elseif timer > 4600 and timer <= 4660 then
		Text.alpha = 1/60*(4660 - timer)
		Text2.alpha = 1/60*(4660 - timer)
		Text3.alpha = 1/60*(4660 - timer)
	elseif timer == 4661 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Phase 2")
		Text3.Set("Credits/Phase 2")
	elseif timer > 5400 and timer <= 5460 then
		Text.alpha = 1/60*(timer - 5400)
		Text2.alpha = 1/60*(timer - 5400)
		Text3.alpha = 1/60*(timer - 5400)
	elseif timer > 5800 and timer <= 5860 then
		Text.alpha = 1/60*(5860 - timer)
		Text2.alpha = 1/60*(5860 - timer)
		Text3.alpha = 1/60*(5860 - timer)
	elseif timer == 5861 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Phase 3")
		Text3.Set("Credits/Phase 3")
	elseif timer > 6400 and timer <= 6460 then
		Text.alpha = 1/60*(timer - 6400)
		Text2.alpha = 1/60*(timer - 6400)
		Text3.alpha = 1/60*(timer - 6400)
	elseif timer > 7000 and timer <= 7060 then
		Text.alpha = 1/60*(7060 - timer)
		Text2.alpha = 1/60*(7060 - timer)
		Text3.alpha = 1/60*(7060 - timer)
	elseif timer == 7061 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Phase 4")
		Text3.Set("Credits/Phase 4")
	elseif timer > 7800 and timer <= 7860 then
		Text.alpha = 1/60*(timer - 7800)
		Text2.alpha = 1/60*(timer - 7800)
		Text3.alpha = 1/60*(timer - 7800)
	elseif timer > 8200 and timer <= 8260 then
		Text.alpha = 1/60*(8260 - timer)
		Text2.alpha = 1/60*(8260 - timer)
		Text3.alpha = 1/60*(8260 - timer)
	elseif timer == 8261 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Blaster")
		Text3.Set("Credits/GB")
	elseif timer > 8800 and timer <= 8860 then
		Text.alpha = 1/60*(timer - 8800)
		Text2.alpha = 1/60*(timer - 8800)
		Text3.alpha = 1/60*(timer - 8800)
	elseif timer > 9400 and timer <= 9460 then
		Text.alpha = 1/60*(9460 - timer)
		Text2.alpha = 1/60*(9460 - timer)
		Text3.alpha = 1/60*(9460 - timer)
	elseif timer == 9461 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Music")
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Theme 1")
		Text2.MoveTo(320, 380)
		Text3.Remove()
		Text3 = nil
	elseif timer > 10000 and timer <= 10060 then
		Text.alpha = 1/60*(timer - 10000)
		Text2.alpha = 1/60*(timer - 10000)
	elseif timer > 10600 and timer <= 10660 then
		Text.alpha = 1/60*(10660 - timer)
		Text2.alpha = 1/60*(10660 - timer)
	elseif timer == 10661 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Theme 2")
	elseif timer > 11200 and timer <= 11260 then
		Text.alpha = 1/60*(timer - 11200)
		Text2.alpha = 1/60*(timer - 11200)
	elseif timer > 11800 and timer <= 11860 then
		Text.alpha = 1/60*(11860 - timer)
		Text2.alpha = 1/60*(11860 - timer)
	elseif timer == 11861 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Theme 3")
	elseif timer > 12400 and timer <= 12460 then
		Text.alpha = 1/60*(timer - 12400)
		Text2.alpha = 1/60*(timer - 12400)
	elseif timer > 13000 and timer <= 13060 then
		Text.alpha = 1/60*(13060 - timer)
		Text2.alpha = 1/60*(13060 - timer)
	elseif timer == 13061 then
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Song 2")
		Text2.MoveTo(320, 360)
	elseif timer > 13800 and timer <= 13860 then
		Text.alpha = 1/60*(timer - 13800)
		Text2.alpha = 1/60*(timer - 13800)
	elseif timer > 14200 and timer <= 14260 then
		Text.alpha = 1/60*(14260 - timer)
		Text2.alpha = 1/60*(14260 - timer)
	elseif timer == 14261 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Undertale")
		Text.MoveTo(320, 370.5)
	elseif timer > 14800 and timer <= 14860 then
		Text.alpha = 1/60*(timer - 14800)
	elseif timer > 15400 and timer <= 15460 then
		Text.alpha = 1/60*(15460 - timer)
	elseif timer == 15461 then
		Text.Set("Credits/"..GetAlMightyGlobal("Idioma").."/Thanks")
		Text2.Set("Credits/"..GetAlMightyGlobal("Idioma").."/THE END")
		Text.MoveTo(320, 400)
		Text2.MoveTo(320, 200)
	elseif timer > 16000 and timer <= 16120 then
		Text.alpha = 1/120*(timer - 16000)
	elseif timer > 16200 and timer <= 16260 then
		Text2.alpha = 1/60*(timer - 16200)
	elseif timer > 16800 and timer <= 16950 then
		Text.alpha = 1/150*(16950 - timer)
		Text2.alpha = 1/150*(16950 - timer)
	elseif timer == 16951 then
		Text.Remove()
		Text2.Remove()
		Text = nil
		Text2 = nil
		if string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 1) == "0" then
			SetAlMightyGlobal("Archivimentazo", "1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 2))
			Encounter["LogroDesbloqueado"] = {Timer = 0, Icon = 1}
		end
	elseif timer == 17200 then
		Map.Remove()
		BlackD.Remove()
		Black.Remove()
		White.Remove()
		Frisk.Remove()
		for i=1,#Objects3D do
			Objects3D[i].Sprite.Remove()
		end
		Audio["enemydust"] = "enemydust"
		SetAlMightyGlobal("ShortDialog", false)
		Encounter["nextwaves"] = {"Menu"}
		State("DEFENDING")
	end
end

function OnHit()
	
end