Shooting satellites works
This commit is contained in:
@@ -17,6 +17,8 @@ namespace EvilSatellites.Screens
|
||||
public ScreenState State { get; set; }
|
||||
private InputManager Input = new InputManager();
|
||||
public List<IGameObject> Objects = new List<IGameObject>();
|
||||
public List<IGameObject> Removable = new List<IGameObject>();
|
||||
public List<IGameObject> Addable = new List<IGameObject>();
|
||||
private Quadtree<IGameObject> objtree = new Quadtree<IGameObject>(new Vector3(10000, 10000, 10000), 10, 20);
|
||||
private float Theta = 0;
|
||||
private Player _player;
|
||||
@@ -29,6 +31,7 @@ namespace EvilSatellites.Screens
|
||||
_player = player;
|
||||
Satellite prop = new Satellite(this, new Vector3(15, 0, 15));
|
||||
Objects.Add(prop);
|
||||
if (_player == null) Environment.Exit(1);
|
||||
ObjectRadar = new Radar(_player, this);
|
||||
return;
|
||||
}
|
||||
@@ -41,11 +44,24 @@ namespace EvilSatellites.Screens
|
||||
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
foreach (var obj in Removable)
|
||||
{
|
||||
Objects.Remove(obj);
|
||||
}
|
||||
if (Addable.Count > 0)
|
||||
{
|
||||
foreach (var obj in Addable)
|
||||
{
|
||||
Objects.Add(obj);
|
||||
}
|
||||
Addable.Clear();
|
||||
}
|
||||
Removable.Clear();
|
||||
objtree.Clear();
|
||||
foreach (var obj in Objects)
|
||||
foreach (var obj in Objects)
|
||||
{
|
||||
objtree.Add(obj);
|
||||
obj.Update(gameTime);
|
||||
objtree.Add(obj);
|
||||
if (obj.Type == ObjectType.Player)
|
||||
{
|
||||
Manager.Sound.ListenerPosition = new System.Numerics.Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z);
|
||||
@@ -55,16 +71,21 @@ namespace EvilSatellites.Screens
|
||||
Manager.Listener.Forward = obj.Rotation.Forward;
|
||||
Manager.Listener.Up = obj.Rotation.Up;
|
||||
}
|
||||
if (obj.ShouldDestroy)
|
||||
{
|
||||
Removable.Add(obj);
|
||||
}
|
||||
}
|
||||
UpdateRadar();
|
||||
CheckCollisions();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void UpdateRadar()
|
||||
{
|
||||
var candidates = objtree.Find(_player.Position, _player.Dimensions);
|
||||
ObjectRadar.Update(Objects);
|
||||
var candidates = objtree.Find(_player.Position, new Vector3(1000, 1000, 1000));
|
||||
ObjectRadar.Update(candidates);
|
||||
}
|
||||
|
||||
public void HandleInput(GameTime gameTime, KeyboardState inputs)
|
||||
@@ -130,16 +151,21 @@ namespace EvilSatellites.Screens
|
||||
ObjectRadar.Start();
|
||||
}
|
||||
}
|
||||
if (Input.IsJustPressed(Keys.O))
|
||||
{
|
||||
Tolk.Speak(Objects.Count.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckCollisions()
|
||||
{
|
||||
foreach (var obj in Objects)
|
||||
{
|
||||
if (!obj.Active) continue;
|
||||
var candidates = objtree.Find(obj.Position, obj.Dimensions);
|
||||
foreach (var target in candidates)
|
||||
{
|
||||
if (obj == target) continue;
|
||||
if (obj == target || !target.Active) continue;
|
||||
if (Intersects(obj, target))
|
||||
{
|
||||
obj.OnCollision(target);
|
||||
@@ -153,5 +179,10 @@ namespace EvilSatellites.Screens
|
||||
{
|
||||
return (obj1.Position.X <= (obj2.Position.X + obj2.Dimensions.X) && (obj1.Position.X + obj1.Dimensions.X) >= obj2.Position.X) && (obj1.Position.Y <= (obj2.Position.Y + obj2.Dimensions.Y) && (obj1.Position.Y + obj1.Dimensions.Y) >= obj2.Position.Y) && (obj1.Position.Z <= (obj2.Position.Z + obj2.Dimensions.Z) && (obj1.Position.Z + obj1.Dimensions.Z) >= obj2.Position.Z);
|
||||
}
|
||||
|
||||
public void AddObject(IGameObject obj)
|
||||
{
|
||||
Addable.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user