68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Xna.Framework;
|
|
using EvilSatellites.Objects;
|
|
using EvilSatellites.Screens;
|
|
|
|
namespace EvilSatellites
|
|
{
|
|
public class SatelliteSpawner
|
|
{
|
|
public GameScreen Screen;
|
|
private Random rnd = new Random();
|
|
private int Level;
|
|
private double RespawnTimer;
|
|
private bool IsRespawning;
|
|
public SatelliteSpawner(GameScreen screen)
|
|
{
|
|
Screen = screen;
|
|
Level = 1;
|
|
}
|
|
|
|
public void Spawn()
|
|
{
|
|
for (var i = 0; i < Level*2; i++)
|
|
{
|
|
var player = Screen.Objects.Where((x) => x.Type == ObjectType.Player).FirstOrDefault();
|
|
var x = player.Position.X-250f + (float)rnd.NextDouble() * 500;
|
|
var y = player.Position.Y - 250f + (float)rnd.NextDouble() * 500;
|
|
var z = player.Position.Z - 250f + (float)rnd.NextDouble() * 500;
|
|
// DavyKager.Tolk.Speak("Spawning sat at " + x.ToString() + ", " + y.ToString() + ", " + z.ToString());
|
|
var sat = new Satellite(Screen, new Vector3(x, y, z));
|
|
Screen.AddObject(sat);
|
|
}
|
|
Screen.Manager.Sound.PlayOneshot(@"sfx/ui/enemiesDetected.wav");
|
|
IsRespawning = false;
|
|
}
|
|
|
|
public void Update(GameTime time)
|
|
{
|
|
var sats = Screen.Objects.Where((x) => x.Type == ObjectType.Satellite).ToList();
|
|
if (sats.Count < 1 && IsRespawning == false)
|
|
{
|
|
IsRespawning = true;
|
|
RespawnTimer = 0;
|
|
}
|
|
if (IsRespawning)
|
|
{
|
|
RespawnTimer += time.ElapsedGameTime.TotalMilliseconds;
|
|
if (RespawnTimer > 5000)
|
|
{
|
|
GameStats.Wave++;
|
|
Level++;
|
|
Spawn();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|