Spawn a whole bunch of ships

This commit is contained in:
2021-04-19 19:49:13 +02:00
parent faf3a38e93
commit 7b25154e8e
4 changed files with 54 additions and 4 deletions
Binary file not shown.
+1 -1
View File
@@ -49,7 +49,7 @@ namespace EvilSatellites
public void Update(List<IGameObject> objects) public void Update(List<IGameObject> objects)
{ {
if (objects.Count < 1) return; if (objects.Count < 1) return;
float minDistance = 1000; float minDistance = 50000000;
Target = null; Target = null;
foreach (var obj in objects) foreach (var obj in objects)
{ {
+42
View File
@@ -0,0 +1,42 @@
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;
public SatelliteSpawner(GameScreen screen)
{
Screen = screen;
Level = 1;
}
public void Spawn()
{
for (var i = 0; i < Level*20; 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);
}
}
public void Update()
{
}
}
}
+11 -3
View File
@@ -23,15 +23,18 @@ namespace EvilSatellites.Screens
private float Theta = 0; private float Theta = 0;
private Player _player; private Player _player;
private Radar ObjectRadar; private Radar ObjectRadar;
private SatelliteSpawner Spawner;
public void Activate() public void Activate()
{ {
State = ScreenState.Active; State = ScreenState.Active;
Player player = new Player(this); Player player = new Player(this);
Objects.Add(player); Objects.Add(player);
_player = player; _player = player;
Satellite prop = new Satellite(this, new Vector3(5000, 5000, 5000)); // Satellite prop = new Satellite(this, new Vector3(5000, 5000, 5000));
Objects.Add(prop); // Objects.Add(prop);
ObjectRadar = new Radar(_player, this); ObjectRadar = new Radar(_player, this);
Spawner = new SatelliteSpawner(this);
Spawner.Spawn();
return; return;
} }
@@ -83,7 +86,7 @@ namespace EvilSatellites.Screens
private void UpdateRadar() private void UpdateRadar()
{ {
var candidates = objtree.Find(_player.Position, new Vector3(1000, 1000, 1000)); var candidates = objtree.Find(_player.Position, new Vector3(1000, 1000, 1000));
ObjectRadar.Update(candidates); ObjectRadar.Update(Objects);
} }
public void HandleInput(GameTime gameTime, KeyboardState inputs) public void HandleInput(GameTime gameTime, KeyboardState inputs)
@@ -176,6 +179,11 @@ namespace EvilSatellites.Screens
Tolk.Output("Satellites"); Tolk.Output("Satellites");
} }
} }
if (Input.IsJustPressed(Keys.O))
{
DavyKager.Tolk.Output(Objects.Count.ToString());
}
} }
private void CheckCollisions() private void CheckCollisions()