Shooting satellites works
This commit is contained in:
Binary file not shown.
@@ -38,10 +38,14 @@ namespace EvilSatellites.Objects
|
|||||||
public IScreen Screen;
|
public IScreen Screen;
|
||||||
public ObjectType Type { get; set; }
|
public ObjectType Type { get; set; }
|
||||||
public bool IsDynamic { get => true; }
|
public bool IsDynamic { get => true; }
|
||||||
|
public bool ShouldDestroy { get; set; }
|
||||||
|
public bool Active { get; set; }
|
||||||
public AbstractGameObject(IScreen screen)
|
public AbstractGameObject(IScreen screen)
|
||||||
{
|
{
|
||||||
Screen = screen;
|
Screen = screen;
|
||||||
Type = ObjectType.Generic;
|
Type = ObjectType.Generic;
|
||||||
|
ShouldDestroy = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RotateX(float angle)
|
public void RotateX(float angle)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace EvilSatellites.Objects
|
|||||||
ObjectType Type { get; set; }
|
ObjectType Type { get; set; }
|
||||||
void Move(Vector3 pose);
|
void Move(Vector3 pose);
|
||||||
void OnCollision(IGameObject obj);
|
void OnCollision(IGameObject obj);
|
||||||
|
bool ShouldDestroy { get; }
|
||||||
|
bool Active { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ namespace EvilSatellites.Objects
|
|||||||
public enum ObjectType
|
public enum ObjectType
|
||||||
{
|
{
|
||||||
Generic,
|
Generic,
|
||||||
Player
|
Player,
|
||||||
|
Satellite,
|
||||||
|
Projectile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,15 @@ namespace EvilSatellites.Objects
|
|||||||
public IWeapon CurrentWeapon;
|
public IWeapon CurrentWeapon;
|
||||||
public Player(IScreen screen): base(screen)
|
public Player(IScreen screen): base(screen)
|
||||||
{
|
{
|
||||||
|
ShouldDestroy = false;
|
||||||
|
Active = true;
|
||||||
Type = ObjectType.Player;
|
Type = ObjectType.Player;
|
||||||
Position = new Vector3(10, 0, 0);
|
Position = new Vector3(10, 0, 0);
|
||||||
Dimensions = new Vector3(5, 5, 5);
|
Dimensions = new Vector3(5, 5, 5);
|
||||||
Movement = new Vector3(0, 0, 0);
|
Movement = new Vector3(0, 0, 0);
|
||||||
Rotation = Matrix.Identity;
|
Rotation = Matrix.Identity;
|
||||||
Orientation = Rotation.Forward;
|
Orientation = Rotation.Forward;
|
||||||
CurrentWeapon = new LaserMG(this, Screen);
|
CurrentWeapon = new LaserMG(this, (GameScreen)Screen);
|
||||||
Activate();
|
Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SynthySound;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using EvilSatellites.Screens;
|
||||||
|
|
||||||
|
namespace EvilSatellites.Objects
|
||||||
|
{
|
||||||
|
public class Projectile : AbstractGameObject
|
||||||
|
{
|
||||||
|
private ISoundEffect3D Sound;
|
||||||
|
private Vector3 Direction;
|
||||||
|
private Vector3 StartPos;
|
||||||
|
private float Range;
|
||||||
|
public Projectile(IScreen screen, Vector3 pos, Vector3 direction) : base(screen)
|
||||||
|
{
|
||||||
|
StartPos = pos;
|
||||||
|
Position = pos;
|
||||||
|
Dimensions = new Vector3(5, 5, 5);
|
||||||
|
Direction = direction;
|
||||||
|
Range = 500;
|
||||||
|
Type = ObjectType.Projectile;
|
||||||
|
Activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Activate()
|
||||||
|
{
|
||||||
|
ShouldDestroy = false;
|
||||||
|
Active = true;
|
||||||
|
}
|
||||||
|
public override void Destroy()
|
||||||
|
{
|
||||||
|
ShouldDestroy = true;
|
||||||
|
Active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
Position += Direction;
|
||||||
|
if (Vector3.Distance(StartPos, Position) > Range)
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnCollision(IGameObject obj)
|
||||||
|
{
|
||||||
|
if (obj.Type == ObjectType.Player) return;
|
||||||
|
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/impacts/bullet/1.wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z), Screen.Manager.EnvironmentEffect);
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ namespace EvilSatellites.Objects
|
|||||||
private ISoundEffect3D Sound;
|
private ISoundEffect3D Sound;
|
||||||
public Satellite(IScreen screen, Vector3 pos) : base(screen)
|
public Satellite(IScreen screen, Vector3 pos) : base(screen)
|
||||||
{
|
{
|
||||||
|
Type = ObjectType.Satellite;
|
||||||
Sound = Screen.Manager.Sound.Load3D(@"sfx/satellite/1/loop.wav");
|
Sound = Screen.Manager.Sound.Load3D(@"sfx/satellite/1/loop.wav");
|
||||||
Sound.Loop = true;
|
Sound.Loop = true;
|
||||||
Position = pos;
|
Position = pos;
|
||||||
@@ -26,6 +27,8 @@ namespace EvilSatellites.Objects
|
|||||||
public override void Activate()
|
public override void Activate()
|
||||||
{
|
{
|
||||||
Sound.Play();
|
Sound.Play();
|
||||||
|
Active = true;
|
||||||
|
ShouldDestroy = false;
|
||||||
}
|
}
|
||||||
public override void Destroy()
|
public override void Destroy()
|
||||||
{
|
{
|
||||||
@@ -39,7 +42,7 @@ namespace EvilSatellites.Objects
|
|||||||
|
|
||||||
public override void OnCollision(IGameObject obj)
|
public override void OnCollision(IGameObject obj)
|
||||||
{
|
{
|
||||||
Sound.Stop();
|
// Sound.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,11 @@ namespace EvilSatellites
|
|||||||
|
|
||||||
public void Update(List<IGameObject> objects)
|
public void Update(List<IGameObject> objects)
|
||||||
{
|
{
|
||||||
|
if (objects.Count < 1) return;
|
||||||
float minDistance = 1000;
|
float minDistance = 1000;
|
||||||
foreach (var obj in objects)
|
foreach (var obj in objects)
|
||||||
{
|
{
|
||||||
if (obj == Owner) continue;
|
if (obj.Type != ObjectType.Satellite) continue;
|
||||||
float distance = Vector3.Distance(obj.Position, Owner.Position);
|
float distance = Vector3.Distance(obj.Position, Owner.Position);
|
||||||
if (distance < minDistance)
|
if (distance < minDistance)
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,7 @@ namespace EvilSatellites
|
|||||||
Target = obj;
|
Target = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Target == null) return;
|
||||||
Vector3 radarTarget = (Target.Position - Owner.Position);
|
Vector3 radarTarget = (Target.Position - Owner.Position);
|
||||||
radarTarget.Normalize();
|
radarTarget.Normalize();
|
||||||
RadarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(Owner.Rotation.Forward, radarTarget) * 3f, 0, 1);
|
RadarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(Owner.Rotation.Forward, radarTarget) * 3f, 0, 1);
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace EvilSatellites.Screens
|
|||||||
public ScreenState State { get; set; }
|
public ScreenState State { get; set; }
|
||||||
private InputManager Input = new InputManager();
|
private InputManager Input = new InputManager();
|
||||||
public List<IGameObject> Objects = new List<IGameObject>();
|
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 Quadtree<IGameObject> objtree = new Quadtree<IGameObject>(new Vector3(10000, 10000, 10000), 10, 20);
|
||||||
private float Theta = 0;
|
private float Theta = 0;
|
||||||
private Player _player;
|
private Player _player;
|
||||||
@@ -29,6 +31,7 @@ namespace EvilSatellites.Screens
|
|||||||
_player = player;
|
_player = player;
|
||||||
Satellite prop = new Satellite(this, new Vector3(15, 0, 15));
|
Satellite prop = new Satellite(this, new Vector3(15, 0, 15));
|
||||||
Objects.Add(prop);
|
Objects.Add(prop);
|
||||||
|
if (_player == null) Environment.Exit(1);
|
||||||
ObjectRadar = new Radar(_player, this);
|
ObjectRadar = new Radar(_player, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -41,11 +44,24 @@ namespace EvilSatellites.Screens
|
|||||||
|
|
||||||
public void Update(GameTime gameTime)
|
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();
|
objtree.Clear();
|
||||||
foreach (var obj in Objects)
|
foreach (var obj in Objects)
|
||||||
{
|
{
|
||||||
objtree.Add(obj);
|
|
||||||
obj.Update(gameTime);
|
obj.Update(gameTime);
|
||||||
|
objtree.Add(obj);
|
||||||
if (obj.Type == ObjectType.Player)
|
if (obj.Type == ObjectType.Player)
|
||||||
{
|
{
|
||||||
Manager.Sound.ListenerPosition = new System.Numerics.Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z);
|
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.Forward = obj.Rotation.Forward;
|
||||||
Manager.Listener.Up = obj.Rotation.Up;
|
Manager.Listener.Up = obj.Rotation.Up;
|
||||||
}
|
}
|
||||||
|
if (obj.ShouldDestroy)
|
||||||
|
{
|
||||||
|
Removable.Add(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UpdateRadar();
|
UpdateRadar();
|
||||||
CheckCollisions();
|
CheckCollisions();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateRadar()
|
private void UpdateRadar()
|
||||||
{
|
{
|
||||||
var candidates = objtree.Find(_player.Position, _player.Dimensions);
|
var candidates = objtree.Find(_player.Position, new Vector3(1000, 1000, 1000));
|
||||||
ObjectRadar.Update(Objects);
|
ObjectRadar.Update(candidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleInput(GameTime gameTime, KeyboardState inputs)
|
public void HandleInput(GameTime gameTime, KeyboardState inputs)
|
||||||
@@ -130,16 +151,21 @@ namespace EvilSatellites.Screens
|
|||||||
ObjectRadar.Start();
|
ObjectRadar.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Input.IsJustPressed(Keys.O))
|
||||||
|
{
|
||||||
|
Tolk.Speak(Objects.Count.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckCollisions()
|
private void CheckCollisions()
|
||||||
{
|
{
|
||||||
foreach (var obj in Objects)
|
foreach (var obj in Objects)
|
||||||
{
|
{
|
||||||
|
if (!obj.Active) continue;
|
||||||
var candidates = objtree.Find(obj.Position, obj.Dimensions);
|
var candidates = objtree.Find(obj.Position, obj.Dimensions);
|
||||||
foreach (var target in candidates)
|
foreach (var target in candidates)
|
||||||
{
|
{
|
||||||
if (obj == target) continue;
|
if (obj == target || !target.Active) continue;
|
||||||
if (Intersects(obj, target))
|
if (Intersects(obj, target))
|
||||||
{
|
{
|
||||||
obj.OnCollision(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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ namespace EvilSatellites.Weapons
|
|||||||
public ISoundEffect sfxSpindown;
|
public ISoundEffect sfxSpindown;
|
||||||
public ISoundEffect sfxSpinup;
|
public ISoundEffect sfxSpinup;
|
||||||
public ISoundEffect sfxSpinning;
|
public ISoundEffect sfxSpinning;
|
||||||
public IScreen Screen;
|
public GameScreen Screen;
|
||||||
public LaserMG(IGameObject wielder, IScreen screen)
|
public LaserMG(IGameObject wielder, GameScreen screen)
|
||||||
{
|
{
|
||||||
_wielder = wielder;
|
_wielder = wielder;
|
||||||
Screen = screen;
|
Screen = screen;
|
||||||
@@ -76,6 +76,8 @@ namespace EvilSatellites.Weapons
|
|||||||
{
|
{
|
||||||
sfxShoot.Play();
|
sfxShoot.Play();
|
||||||
TimerStart = TimerEnd;
|
TimerStart = TimerEnd;
|
||||||
|
Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation.Forward);
|
||||||
|
Screen.AddObject(proj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.Update(time);
|
base.Update(time);
|
||||||
|
|||||||
Reference in New Issue
Block a user