Arena.Resize(360, 130)

timer = 0
Black1 = CreateSprite("Pixel","Top")
Black1.Scale(135, 130)
Black1.MoveTo(67.5, 160)
Black2 = CreateSprite("Pixel","Top")
Black2.Scale(135, 130)
Black2.MoveTo(572.5, 160)
Black1.color = {0,0,0}
Black2.color = {0,0,0}

Eggs = {}

SetPPCollision(true)

function Update()
	timer = timer + 1
	if timer%90 == 10 then
		if math.random(2) == 1 then
			if math.random(2) == 1 then
				table.insert(Eggs, {Bullet = CreateProjectileAbs("Egg Dog/Bullets/Egg", 125, 160), Rot = math.random(20, 40), VelX = math.random(15, 30), VelY = math.random(15, 30)})
			else
				table.insert(Eggs, {Bullet = CreateProjectileAbs("Egg Dog/Bullets/Egg", 125, 160), Rot = -math.random(20, 40), VelX = math.random(15, 30), VelY = -math.random(15, 30)})
			end
		else
			if math.random(2) == 1 then
				table.insert(Eggs, {Bullet = CreateProjectileAbs("Egg Dog/Bullets/Egg", 515, 160), Rot = math.random(20, 40), VelX = -math.random(15, 30), VelY = math.random(15, 30)})
			else
				table.insert(Eggs, {Bullet = CreateProjectileAbs("Egg Dog/Bullets/Egg", 515, 160), Rot = -math.random(20, 40), VelX = -math.random(15, 30), VelY = -math.random(15, 30)})
			end
		end
	end
	for i=1,#Eggs do
		local Datos = Eggs[i]
		if not Datos.X then
			Datos.X = Datos.Bullet.absx
		end
		if not Datos.Y then
			Datos.Y = Datos.Bullet.absy
		end
		if (Datos.X <= 156 and Datos.VelX < 0) or (Datos.X >= 484 and Datos.VelX > 0) then
			Datos.VelX = -Datos.VelX
		end
		Datos.X = Datos.X + Datos.VelX/10
		if (Datos.Y <= 111 and Datos.VelY < 0) or (Datos.Y >= 209 and Datos.VelY > 0) then
			Datos.VelY = -Datos.VelY
		end
		Datos.Y = Datos.Y + Datos.VelY/10
		Datos.Bullet.MoveToAbs(Datos.X, Datos.Y)
		Datos.Bullet.sprite.rotation = Datos.Bullet.sprite.rotation + Datos.Rot/10
	end
	if timer > 600 then
		Black1.Remove()
		Black2.Remove()
		EndWave()
	end
end

function OnHit()
	if Player.hp > 10 then
		Player.Hurt(10)
	elseif Player.hp > 1 then
		Player.Hurt(1)
	elseif not Player.isHurting then
		Black1.Remove()
		Black2.Remove()
		Encounter["X"] = Player.absx
		Encounter["Y"] = Player.absy
		Encounter["nextwaves"] = {"Game Over"}
		State("ACTIONSELECT")
		State("DEFENDING")
	end
end