diff --git a/.vs/EvilSatellites/v16/.suo b/.vs/EvilSatellites/v16/.suo index 4a133c0..4b9a815 100644 Binary files a/.vs/EvilSatellites/v16/.suo and b/.vs/EvilSatellites/v16/.suo differ diff --git a/EvilSatellites/Objects/AbstractGameObject.cs b/EvilSatellites/Objects/AbstractGameObject.cs index 47ef5cc..c787703 100644 --- a/EvilSatellites/Objects/AbstractGameObject.cs +++ b/EvilSatellites/Objects/AbstractGameObject.cs @@ -24,7 +24,7 @@ namespace EvilSatellites.Objects public Vector3 Movement; private Vector3 _Orientation; public Vector3 Orientation - { + { get => _Orientation; set => _Orientation = value; } @@ -38,10 +38,14 @@ namespace EvilSatellites.Objects public IScreen Screen; public ObjectType Type { get; set; } public bool IsDynamic { get => true; } + public bool ShouldDestroy { get; set; } + public bool Active { get; set; } public AbstractGameObject(IScreen screen) { Screen = screen; Type = ObjectType.Generic; + ShouldDestroy = false; + } public void RotateX(float angle) diff --git a/EvilSatellites/Objects/IGameObject.cs b/EvilSatellites/Objects/IGameObject.cs index 2081aeb..c972383 100644 --- a/EvilSatellites/Objects/IGameObject.cs +++ b/EvilSatellites/Objects/IGameObject.cs @@ -19,6 +19,7 @@ namespace EvilSatellites.Objects ObjectType Type { get; set; } void Move(Vector3 pose); void OnCollision(IGameObject obj); - + bool ShouldDestroy { get; } + bool Active { get; set; } } } diff --git a/EvilSatellites/Objects/ObjectType.cs b/EvilSatellites/Objects/ObjectType.cs index feae8a9..60cdd4b 100644 --- a/EvilSatellites/Objects/ObjectType.cs +++ b/EvilSatellites/Objects/ObjectType.cs @@ -7,6 +7,8 @@ namespace EvilSatellites.Objects public enum ObjectType { Generic, - Player + Player, + Satellite, + Projectile } } diff --git a/EvilSatellites/Objects/Player.cs b/EvilSatellites/Objects/Player.cs index 90761bb..daa2533 100644 --- a/EvilSatellites/Objects/Player.cs +++ b/EvilSatellites/Objects/Player.cs @@ -18,13 +18,15 @@ namespace EvilSatellites.Objects public IWeapon CurrentWeapon; public Player(IScreen screen): base(screen) { + ShouldDestroy = false; + Active = true; Type = ObjectType.Player; Position = new Vector3(10, 0, 0); Dimensions = new Vector3(5, 5, 5); Movement = new Vector3(0, 0, 0); Rotation = Matrix.Identity; Orientation = Rotation.Forward; - CurrentWeapon = new LaserMG(this, Screen); + CurrentWeapon = new LaserMG(this, (GameScreen)Screen); Activate(); } diff --git a/EvilSatellites/Objects/Projectile.cs b/EvilSatellites/Objects/Projectile.cs new file mode 100644 index 0000000..5dbaac8 --- /dev/null +++ b/EvilSatellites/Objects/Projectile.cs @@ -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(); + } + } +} diff --git a/EvilSatellites/Objects/Satellite.cs b/EvilSatellites/Objects/Satellite.cs index 162781e..1e2fde3 100644 --- a/EvilSatellites/Objects/Satellite.cs +++ b/EvilSatellites/Objects/Satellite.cs @@ -14,6 +14,7 @@ namespace EvilSatellites.Objects private ISoundEffect3D Sound; public Satellite(IScreen screen, Vector3 pos) : base(screen) { + Type = ObjectType.Satellite; Sound = Screen.Manager.Sound.Load3D(@"sfx/satellite/1/loop.wav"); Sound.Loop = true; Position = pos; @@ -26,6 +27,8 @@ namespace EvilSatellites.Objects public override void Activate() { Sound.Play(); + Active = true; + ShouldDestroy = false; } public override void Destroy() { @@ -39,7 +42,7 @@ namespace EvilSatellites.Objects public override void OnCollision(IGameObject obj) { - Sound.Stop(); + // Sound.Stop(); } } } diff --git a/EvilSatellites/Radar.cs b/EvilSatellites/Radar.cs index 09ad916..343247d 100644 --- a/EvilSatellites/Radar.cs +++ b/EvilSatellites/Radar.cs @@ -41,10 +41,11 @@ namespace EvilSatellites public void Update(List objects) { + if (objects.Count < 1) return; float minDistance = 1000; foreach (var obj in objects) { - if (obj == Owner) continue; + if (obj.Type != ObjectType.Satellite) continue; float distance = Vector3.Distance(obj.Position, Owner.Position); if (distance < minDistance) { @@ -52,6 +53,7 @@ namespace EvilSatellites Target = obj; } } + if (Target == null) return; Vector3 radarTarget = (Target.Position - Owner.Position); radarTarget.Normalize(); RadarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(Owner.Rotation.Forward, radarTarget) * 3f, 0, 1); diff --git a/EvilSatellites/Screens/GameScreen.cs b/EvilSatellites/Screens/GameScreen.cs index 7b37420..657334f 100644 --- a/EvilSatellites/Screens/GameScreen.cs +++ b/EvilSatellites/Screens/GameScreen.cs @@ -17,6 +17,8 @@ namespace EvilSatellites.Screens public ScreenState State { get; set; } private InputManager Input = new InputManager(); public List Objects = new List(); + public List Removable = new List(); + public List Addable = new List(); private Quadtree objtree = new Quadtree(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); + } } } diff --git a/EvilSatellites/Weapons/LaserMG.cs b/EvilSatellites/Weapons/LaserMG.cs index 22eb0d2..4095c51 100644 --- a/EvilSatellites/Weapons/LaserMG.cs +++ b/EvilSatellites/Weapons/LaserMG.cs @@ -17,8 +17,8 @@ namespace EvilSatellites.Weapons public ISoundEffect sfxSpindown; public ISoundEffect sfxSpinup; public ISoundEffect sfxSpinning; - public IScreen Screen; - public LaserMG(IGameObject wielder, IScreen screen) + public GameScreen Screen; + public LaserMG(IGameObject wielder, GameScreen screen) { _wielder = wielder; Screen = screen; @@ -76,6 +76,8 @@ namespace EvilSatellites.Weapons { sfxShoot.Play(); TimerStart = TimerEnd; + Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation.Forward); + Screen.AddObject(proj); } } base.Update(time);