Files
evilsatellites/EvilSatellites/SatelliteSpawner.cs
T

68 lines
2.0 KiB
C#
Raw Normal View History

2021-04-19 19:49:13 +02:00
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;
2021-04-24 14:34:15 +02:00
private double RespawnTimer;
private bool IsRespawning;
2021-04-19 19:49:13 +02:00
public SatelliteSpawner(GameScreen screen)
{
Screen = screen;
Level = 1;
}
public void Spawn()
{
2021-04-19 21:33:56 +02:00
for (var i = 0; i < Level*2; i++)
2021-04-19 19:49:13 +02:00
{
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);
}
2021-04-24 14:34:15 +02:00
Screen.Manager.Sound.PlayOneshot(@"sfx/ui/enemiesDetected.wav");
IsRespawning = false;
2021-04-19 19:49:13 +02:00
}
2021-04-24 14:34:15 +02:00
public void Update(GameTime time)
2021-04-19 19:49:13 +02:00
{
2021-04-20 16:45:20 +02:00
var sats = Screen.Objects.Where((x) => x.Type == ObjectType.Satellite).ToList();
2021-04-24 14:34:15 +02:00
if (sats.Count < 1 && IsRespawning == false)
2021-04-20 16:45:20 +02:00
{
2021-04-24 14:34:15 +02:00
IsRespawning = true;
RespawnTimer = 0;
}
if (IsRespawning)
{
RespawnTimer += time.ElapsedGameTime.TotalMilliseconds;
if (RespawnTimer > 5000)
{
GameStats.Wave++;
Level++;
Spawn();
}
2021-04-20 16:45:20 +02:00
}
2021-04-19 19:49:13 +02:00
}
2021-04-23 20:28:06 +02:00
public void Destroy()
{
return;
}
2021-04-19 19:49:13 +02:00
}
}