From 2f7759d190a1a11ae1afb146cd070b804a1be955 Mon Sep 17 00:00:00 2001 From: Talon Date: Sun, 11 Apr 2021 17:09:57 +0200 Subject: [PATCH] Add basic radar and weapon --- .vs/EvilSatellites/v16/.suo | Bin 64000 -> 89600 bytes EvilSatellites/AudioAsset.cs | 27 ++---- EvilSatellites/AudioAsset3D.cs | 85 ++++++++++++++++++ EvilSatellites/EvilSatellites.csproj | 2 +- EvilSatellites/InputManager.cs | 47 ++++++++++ EvilSatellites/Objects/AbstractGameObject.cs | 1 + EvilSatellites/Objects/Player.cs | 5 ++ EvilSatellites/Objects/Satellite.cs | 45 ++++++++++ EvilSatellites/Objects/SynthyProp.cs | 1 + EvilSatellites/Radar.cs | 60 +++++++++++++ EvilSatellites/ScreenManager.cs | 2 + EvilSatellites/Screens/GameScreen.cs | 62 ++++++++----- EvilSatellites/{ => Screens}/IScreen.cs | 2 +- EvilSatellites/Weapons/AbstractWeapon.cs | 34 +++++++ EvilSatellites/Weapons/IWeapon.cs | 22 +++++ EvilSatellites/Weapons/LaserMG.cs | 85 ++++++++++++++++++ .../sfx/physics/impacts/bullet/1.wav | 3 + .../sfx/physics/impacts/bullet/2.wav | 3 + .../sfx/physics/impacts/bullet/3.wav | 3 + .../sfx/physics/impacts/bullet/4.wav | 3 + .../sfx/physics/impacts/bullet/5.wav | 3 + .../sfx/physics/impacts/bullet/6.wav | 3 + EvilSatellites/sfx/sattelite/1/loop.wav | 3 + .../sfx/weapons/LaserMG/spindown.wav | 3 + .../sfx/weapons/LaserMG/spinning.wav | 3 + EvilSatellites/sfx/weapons/LaserMG/spinup.wav | 3 + 26 files changed, 465 insertions(+), 45 deletions(-) create mode 100644 EvilSatellites/AudioAsset3D.cs create mode 100644 EvilSatellites/InputManager.cs create mode 100644 EvilSatellites/Objects/Satellite.cs create mode 100644 EvilSatellites/Radar.cs rename EvilSatellites/{ => Screens}/IScreen.cs (93%) create mode 100644 EvilSatellites/Weapons/AbstractWeapon.cs create mode 100644 EvilSatellites/Weapons/IWeapon.cs create mode 100644 EvilSatellites/Weapons/LaserMG.cs create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/1.wav create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/2.wav create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/3.wav create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/4.wav create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/5.wav create mode 100644 EvilSatellites/sfx/physics/impacts/bullet/6.wav create mode 100644 EvilSatellites/sfx/sattelite/1/loop.wav create mode 100644 EvilSatellites/sfx/weapons/LaserMG/spindown.wav create mode 100644 EvilSatellites/sfx/weapons/LaserMG/spinning.wav create mode 100644 EvilSatellites/sfx/weapons/LaserMG/spinup.wav diff --git a/.vs/EvilSatellites/v16/.suo b/.vs/EvilSatellites/v16/.suo index 74fd04e30de3c0feab20e1660b5eb3be2aaa763f..4a133c095ef94a95057eb2c1fb31757644bc4ac3 100644 GIT binary patch delta 6997 zcmeHL3tUuX7Qf#xgUm2IhPS9VAPNc^gyKqQh=YoP@(@8GVSq_78DJhh5Sua0U%JZ1 zoL)<0NNrnYn|WI^GaW?TZTl%?X0`36SnX0l`69Lb8GFv1ha;l3t-IUqZ@=IC=bn4M z$NBF0zVCm|z2=K<=6#ZfLm7Zk8pT#OWX}z#L;V`W{Rk7njIfB7Nvtsk8qo)${ytbiK5);&Rwo(M zy49L$QFJ(hj8gGN9XZ7HLCGOPrTvebL-j#;4Yt>jBdB^PUI!y+41c_aAOaD7h#?41 zgckxIT*if?K%LNW;=9-?cwIa(z8Q5>5l;7^oQjx+P$9Aq)W=amAzU(?<)M?=l7{Tr z&@71#*JB$4!iZRoSb@k*Jm2CgIl~s5UKP9U!`0^DAt_)a&H^p{^+EMXPcqHtQcu1*L6)LOkX2gN66I*3( z{#}DQ*pj63V0a&cpuNi*k~T9KAO6oxb-ZJ$w43q~1&9TRg@{5#5rQU3PeIobyn;DA zTA2AVys31~yuW*?InI29#WxZn` zz4%`PMt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B ze>}ABec5kLkyroG>n)x6H4k;+pB5%{5})5D+t>P4IM>1{<+l9X($HCTav28nw80NHWr7*yjZ-rG8n~*M37+$ufbCl z@px^87N1^OgK=vUaj;yA%gfVMm#^KuY*{xB_g2op#_|VITb_>I@)E3HJsS<4lVNpS z4Y!$lf_t2^OTy8|VCpyn*T7W}JGolUP8Zrv&cNp#AudayHb9(>CV-l4)Xn1WxLG=}W`Nfixksq4o~}8tyD+?s)6gF&@o%!%Yfgc5DH zL~OgF#KR3)*nL&iu|vi;Sa9%4KCT^5;R6FdL*p+`ptnkaigURgPX*(N<~Xc8_o6!E z-cadYc561(0T9dwM4dLHDV3&O>@L^)$$Grto+QAF_|6iz4yVO2%eDXkl^xueZsr#w|#s&1}lSDCo@@%?t?9;%6#xv(VbxKfz zT6HhzQ@tz!Wcc$3g)AC+vpqM%$w%VP9|AS|w!T}kyqTmFOSW4V;S~+|a~mq34RcQg zSb(MVq4yL#Hd-oY|3{p3eBefql<|cC^b!w{fqkxWfMv$D z{hzw8M}VMYU;0|+iYIGZq{D+@K)+Di^6P5t)thSF)_7R{Z5KQ|n58Cvf63)k{y#1b z)x#NXuMTwh<#3eTO7}xGE*hEvAz1p4ScsNj_%^s}=0T&o`wf%a!B^{9Ub|a7Crn_3e*&B@*`)vg diff --git a/EvilSatellites/AudioAsset.cs b/EvilSatellites/AudioAsset.cs index f45795f..c9961a7 100644 --- a/EvilSatellites/AudioAsset.cs +++ b/EvilSatellites/AudioAsset.cs @@ -9,31 +9,17 @@ namespace EvilSatellites { public class AudioAsset { - private List _SoundList { get; set; } + private List _SoundList { get; set; } private string _Path; private Synthy _Engine; - private Vector3 _Position; - public Vector3 Position - { - get - { - return _Position; - } - set - { - _Position = value; - foreach (var sound in _SoundList) - { - sound.Position = value; - } - } - } private Random rnd; private int _Min; private int _Max; - public AudioAsset(Synthy engine, string path, int min, int max) + private bool IsPanning = false; + public AudioAsset(Synthy engine, string path, int min, int max, bool panning = false) { - _SoundList = new List(); + IsPanning = panning; + _SoundList = new List(); _Engine = engine; _Path = path; _Max = max; @@ -46,8 +32,7 @@ namespace EvilSatellites { for (var i = _Min; i <= _Max; i++) { - Console.WriteLine(_Path + "/" + i.ToString() + ".wav"); - _SoundList.Add(_Engine.Load3D(_Path + "/" + i.ToString() + ".wav")); + _SoundList.Add(_Engine.Load(_Path + "/" + i.ToString() + ".wav", IsPanning)); } } diff --git a/EvilSatellites/AudioAsset3D.cs b/EvilSatellites/AudioAsset3D.cs new file mode 100644 index 0000000..3a2939a --- /dev/null +++ b/EvilSatellites/AudioAsset3D.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; +using XVector3 = Microsoft.Xna.Framework.Vector3; +using System.Numerics; +using SynthySound; + +namespace EvilSatellites +{ + public class AudioAsset3D + { + private List _SoundList { get; set; } + private string _Path; + private Synthy _Engine; + private Vector3 _Position; + public Vector3 Position + { + get + { + return _Position; + } + set + { + _Position = value; + foreach (var sound in _SoundList) + { + sound.Position = value; + } + } + } + private Random rnd; + private int _Min; + private int _Max; + public AudioAsset3D(Synthy engine, string path, int min, int max) + { + _SoundList = new List(); + _Engine = engine; + _Path = path; + _Max = max; + _Min = min; + rnd = new Random(); + LoadAssets(); + } + + private void LoadAssets() + { + for (var i = _Min; i <= _Max; i++) + { + Console.WriteLine(_Path + "/" + i.ToString() + ".wav"); + _SoundList.Add(_Engine.Load3D(_Path + "/" + i.ToString() + ".wav")); + } + } + + public void Play() + { + var index = rnd.Next(_SoundList.Count); + _SoundList[index].Reset(); + _SoundList[index].Play(); + } + + public void AddEffect(IEffect effect) + { + foreach (var sound in _SoundList) + { + sound.ConnectToEffect(effect); + } + } + + public void RemoveEffect(IEffect effect) + { + foreach (var sound in _SoundList) + { + sound.DisconnectFromEffect(effect); + } + } + + public void Dispose() + { + foreach (var sound in _SoundList) + { + sound.Destroy(); + } + } + } +} diff --git a/EvilSatellites/EvilSatellites.csproj b/EvilSatellites/EvilSatellites.csproj index c592fcb..57592a4 100644 --- a/EvilSatellites/EvilSatellites.csproj +++ b/EvilSatellites/EvilSatellites.csproj @@ -1,4 +1,4 @@ - + WinExe net5.0 diff --git a/EvilSatellites/InputManager.cs b/EvilSatellites/InputManager.cs new file mode 100644 index 0000000..8891bbb --- /dev/null +++ b/EvilSatellites/InputManager.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Input; + + +namespace EvilSatellites +{ + public class InputManager + { + private KeyboardState OldKeyState; + private KeyboardState NewKeyState; + public InputManager() + { + OldKeyState = Keyboard.GetState(); + NewKeyState = Keyboard.GetState(); + } + + public void Update() + { + OldKeyState = NewKeyState; + NewKeyState = Keyboard.GetState(); + } + + public bool IsJustPressed(Keys key) + { + return (NewKeyState.IsKeyDown(key) && !OldKeyState.IsKeyDown(key)); + } + + public bool IsJustReleased(Keys key) + { + return !NewKeyState.IsKeyDown(key) && OldKeyState.IsKeyDown(key); + } + + public bool IsPressed(Keys key) + { + return NewKeyState.IsKeyDown(key); + } + + public bool IsReleased(Keys key) + { + return NewKeyState.IsKeyUp(key); + } + } +} diff --git a/EvilSatellites/Objects/AbstractGameObject.cs b/EvilSatellites/Objects/AbstractGameObject.cs index 4bbc64d..47ef5cc 100644 --- a/EvilSatellites/Objects/AbstractGameObject.cs +++ b/EvilSatellites/Objects/AbstractGameObject.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; +using EvilSatellites.Screens; namespace EvilSatellites.Objects { diff --git a/EvilSatellites/Objects/Player.cs b/EvilSatellites/Objects/Player.cs index c23bf77..90761bb 100644 --- a/EvilSatellites/Objects/Player.cs +++ b/EvilSatellites/Objects/Player.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using SynthySound; +using EvilSatellites.Screens; +using EvilSatellites.Weapons; namespace EvilSatellites.Objects { @@ -13,6 +15,7 @@ namespace EvilSatellites.Objects private Vector3 Deceleration = new Vector3(0.005f, 0.005f, 0.005f); private ISoundEffect sfxEngine; private ISoundEffect sfxWhine; + public IWeapon CurrentWeapon; public Player(IScreen screen): base(screen) { Type = ObjectType.Player; @@ -21,6 +24,7 @@ namespace EvilSatellites.Objects Movement = new Vector3(0, 0, 0); Rotation = Matrix.Identity; Orientation = Rotation.Forward; + CurrentWeapon = new LaserMG(this, Screen); Activate(); } @@ -43,6 +47,7 @@ namespace EvilSatellites.Objects } override public void Update(GameTime gameTime) { + CurrentWeapon.Update(gameTime); Move(Movement); sfxEngine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 4; sfxWhine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 1; diff --git a/EvilSatellites/Objects/Satellite.cs b/EvilSatellites/Objects/Satellite.cs new file mode 100644 index 0000000..162781e --- /dev/null +++ b/EvilSatellites/Objects/Satellite.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SynthySound; +using EvilSatellites.Screens; +using Microsoft.Xna.Framework; + +namespace EvilSatellites.Objects +{ + public class Satellite : AbstractGameObject + { + private ISoundEffect3D Sound; + public Satellite(IScreen screen, Vector3 pos) : base(screen) + { + Sound = Screen.Manager.Sound.Load3D(@"sfx/satellite/1/loop.wav"); + Sound.Loop = true; + Position = pos; + Dimensions = new Vector3(5, 5, 5); + Sound.Position = new System.Numerics.Vector3(pos.X, pos.Y, pos.Z); + Sound.ConnectToEffect(Screen.Manager.EnvironmentEffect); + Activate(); + } + + public override void Activate() + { + Sound.Play(); + } + public override void Destroy() + { + Sound.Destroy(); + } + + override public void Update(GameTime gameTime) + { + Sound.Position = new System.Numerics.Vector3(Position.X, Position.Y, Position.Z); + } + + public override void OnCollision(IGameObject obj) + { + Sound.Stop(); + } + } +} diff --git a/EvilSatellites/Objects/SynthyProp.cs b/EvilSatellites/Objects/SynthyProp.cs index 4da4165..f9cd0e7 100644 --- a/EvilSatellites/Objects/SynthyProp.cs +++ b/EvilSatellites/Objects/SynthyProp.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using SynthySound; +using EvilSatellites.Screens; namespace EvilSatellites.Objects { diff --git a/EvilSatellites/Radar.cs b/EvilSatellites/Radar.cs new file mode 100644 index 0000000..09ad916 --- /dev/null +++ b/EvilSatellites/Radar.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SynthySound; +using EvilSatellites.Screens; +using EvilSatellites.Objects; +using Microsoft.Xna.Framework; + +namespace EvilSatellites +{ + public class Radar + { + public bool Active { get; set; } + public IGameObject Owner; + public IGameObject Target; + public IScreen Screen; + public ISoundEffect RadarNoise; + public Radar(IGameObject owner, IScreen screen) + { + Owner = owner; + Screen = screen; + RadarNoise = Screen.Manager.Sound.Load(@"sfx/ui/radar/pingEnemy.wav", false); + RadarNoise.Loop = true; + Active = false; + } + + public void Start() + { + RadarNoise.Reset(); + RadarNoise.Play(); + Active = true; + } + + public void Stop() + { + RadarNoise.Pause(); + Active = false; + } + + public void Update(List objects) + { + float minDistance = 1000; + foreach (var obj in objects) + { + if (obj == Owner) continue; + float distance = Vector3.Distance(obj.Position, Owner.Position); + if (distance < minDistance) + { + minDistance = distance; + Target = obj; + } + } + 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/ScreenManager.cs b/EvilSatellites/ScreenManager.cs index 5fbff77..fdfd54f 100644 --- a/EvilSatellites/ScreenManager.cs +++ b/EvilSatellites/ScreenManager.cs @@ -5,6 +5,8 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using SynthySound; using Microsoft.Xna.Framework.Audio; +using EvilSatellites.Screens; + namespace EvilSatellites { diff --git a/EvilSatellites/Screens/GameScreen.cs b/EvilSatellites/Screens/GameScreen.cs index 92a7bbf..7b37420 100644 --- a/EvilSatellites/Screens/GameScreen.cs +++ b/EvilSatellites/Screens/GameScreen.cs @@ -15,22 +15,21 @@ namespace EvilSatellites.Screens { public ScreenManager Manager { get; set; } public ScreenState State { get; set; } + private InputManager Input = new InputManager(); public List Objects = new List(); private Quadtree objtree = new Quadtree(new Vector3(10000, 10000, 10000), 10, 20); private float Theta = 0; private Player _player; - private ISoundEffect radarNoise; + private Radar ObjectRadar; public void Activate() { State = ScreenState.Active; Player player = new Player(this); Objects.Add(player); _player = player; - SynthyProp prop = new SynthyProp(this, new Vector3(15, 0, 15)); + Satellite prop = new Satellite(this, new Vector3(15, 0, 15)); Objects.Add(prop); - radarNoise = Manager.Sound.Load(@"sfx/ui/voiceError.wav", false); - radarNoise.Loop = true; - radarNoise.Play(); + ObjectRadar = new Radar(_player, this); return; } @@ -57,61 +56,80 @@ namespace EvilSatellites.Screens Manager.Listener.Up = obj.Rotation.Up; } } - Vector3 radarTarget = (Objects[1].Position - _player.Position); - radarTarget.Normalize(); - radarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(_player.Rotation.Forward, radarTarget)*3f, 0, 1); + UpdateRadar(); CheckCollisions(); return; } + private void UpdateRadar() + { + var candidates = objtree.Find(_player.Position, _player.Dimensions); + ObjectRadar.Update(Objects); + } + public void HandleInput(GameTime gameTime, KeyboardState inputs) { + Input.Update(); Vector3 move = new Vector3(0, 0, 0); - if (inputs.IsKeyDown(Keys.W)) + if (Input.IsPressed(Keys.W)) { move.Z = -0.035f; } - if (inputs.IsKeyDown(Keys.S)) + if (Input.IsPressed(Keys.S)) { move.Z = 0.035f; } - if (inputs.IsKeyDown(Keys.A)) + if (Input.IsPressed(Keys.A)) { move.X = -0.035f; } - if (inputs.IsKeyDown(Keys.D)) + if (Input.IsPressed(Keys.D)) { move.X = 0.035f; } - if (inputs.IsKeyDown(Keys.Left)) + if (Input.IsPressed(Keys.Left)) { _player.RotateY(0.05f); } - if (inputs.IsKeyDown(Keys.Right)) + if (Input.IsPressed(Keys.Right)) { _player.RotateY(-0.05f); } - if (inputs.IsKeyDown(Keys.Up)) + if (Input.IsPressed(Keys.Up)) { _player.RotateX(0.05f); } - if (inputs.IsKeyDown(Keys.Down)) + if (Input.IsPressed(Keys.Down)) { _player.RotateX(-0.05f); } _player.Accelerate(move); - if (inputs.IsKeyDown(Keys.V)) + if (Input.IsJustPressed(Keys.Space)) + { + _player.CurrentWeapon.Shoot(gameTime); + } + if (Input.IsJustReleased(Keys.Space)) + { + _player.CurrentWeapon.Stop(); + } + if (Input.IsJustPressed(Keys.V)) { Tolk.Speak(_player.Movement.Length().ToString(), true); } - if (inputs.IsKeyDown(Keys.X)) - { - Tolk.Speak(radarNoise.Pitch.ToString(), true); - } - if (inputs.IsKeyDown(Keys.C)) + if (Input.IsJustPressed(Keys.C)) { Tolk.Speak(_player.Position.ToString()); } + if (Input.IsJustPressed(Keys.R)) + { + if (ObjectRadar.Active) + { + ObjectRadar.Stop(); + } else + { + ObjectRadar.Start(); + } + } } private void CheckCollisions() diff --git a/EvilSatellites/IScreen.cs b/EvilSatellites/Screens/IScreen.cs similarity index 93% rename from EvilSatellites/IScreen.cs rename to EvilSatellites/Screens/IScreen.cs index cadba8d..a2a62e5 100644 --- a/EvilSatellites/IScreen.cs +++ b/EvilSatellites/Screens/IScreen.cs @@ -4,7 +4,7 @@ using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; -namespace EvilSatellites +namespace EvilSatellites.Screens { public interface IScreen { diff --git a/EvilSatellites/Weapons/AbstractWeapon.cs b/EvilSatellites/Weapons/AbstractWeapon.cs new file mode 100644 index 0000000..70117de --- /dev/null +++ b/EvilSatellites/Weapons/AbstractWeapon.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EvilSatellites.Objects; +using Microsoft.Xna.Framework; + +namespace EvilSatellites.Weapons +{ + public enum WeaponState + { + Stopped, + Starting, + Firing, + Stopping + } + + public class AbstractWeapon : IWeapon + { + public IGameObject _wielder; + public float FireRate { get; set; } + public int MaxAmmo { get; set; } + public int RemainingAmmo { get; set; } + public WeaponState State { get; set; } + public double TimerStart; + public double TimerEnd; + public virtual void Shoot(GameTime time) { } + public virtual void Reload() { } + public virtual void Stop() { } + public virtual void Update(GameTime time) { } + + } +} diff --git a/EvilSatellites/Weapons/IWeapon.cs b/EvilSatellites/Weapons/IWeapon.cs new file mode 100644 index 0000000..cc7cf10 --- /dev/null +++ b/EvilSatellites/Weapons/IWeapon.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EvilSatellites.Weapons; +using Microsoft.Xna.Framework; + +namespace EvilSatellites.Weapons +{ + public interface IWeapon + { + void Shoot(GameTime time); + void Reload(); + void Stop(); + void Update(GameTime time); + float FireRate { get; set; } + int MaxAmmo { get; set; } + int RemainingAmmo { get; set; } + WeaponState State { get; set; } + } +} diff --git a/EvilSatellites/Weapons/LaserMG.cs b/EvilSatellites/Weapons/LaserMG.cs new file mode 100644 index 0000000..22eb0d2 --- /dev/null +++ b/EvilSatellites/Weapons/LaserMG.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EvilSatellites.Objects; +using SynthySound; +using EvilSatellites.Screens; +using Microsoft.Xna.Framework; + +namespace EvilSatellites.Weapons +{ + public class LaserMG : AbstractWeapon + { + public AudioAsset sfxShoot; + public ISoundEffect sfxReload; + public ISoundEffect sfxSpindown; + public ISoundEffect sfxSpinup; + public ISoundEffect sfxSpinning; + public IScreen Screen; + public LaserMG(IGameObject wielder, IScreen screen) + { + _wielder = wielder; + Screen = screen; + MaxAmmo = 250; + RemainingAmmo = MaxAmmo; + FireRate = 90; + State = WeaponState.Stopped; + LoadSounds(); + } + + public void LoadSounds() + { + sfxReload = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/reload.wav", false); + sfxSpindown = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spindown.wav", false); + sfxSpinup = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spinup.wav", false); + sfxSpinning = Screen.Manager.Sound.Load(@"sfx/weapons/LaserMG/spinning.wav", false); + sfxSpinning.Loop = true; + sfxShoot = new AudioAsset(Screen.Manager.Sound, @"sfx/weapons/LaserMG/fire", 1, 4); + } + + public override void Shoot(GameTime time) + { + State = WeaponState.Starting; + sfxSpinup.Reset(); + sfxSpinup.Play(); + TimerStart = time.TotalGameTime.TotalMilliseconds; + } + + public override void Stop() + { + if (State == WeaponState.Firing) + { + sfxSpinning.Pause(); + sfxSpindown.Reset(); + sfxSpindown.Play(); + State = WeaponState.Stopped; + } + } + + public override void Update(GameTime time) + { + TimerEnd += time.ElapsedGameTime.TotalMilliseconds; + if (State == WeaponState.Starting) + { + if (TimerEnd - TimerStart > 800) + { + State = WeaponState.Firing; + sfxSpinning.Play(); + TimerStart = TimerEnd; + } + } + if (State == WeaponState.Firing) + { + if (TimerEnd - TimerStart > FireRate) + { + sfxShoot.Play(); + TimerStart = TimerEnd; + } + } + base.Update(time); + } + + } +} diff --git a/EvilSatellites/sfx/physics/impacts/bullet/1.wav b/EvilSatellites/sfx/physics/impacts/bullet/1.wav new file mode 100644 index 0000000..b716b0f --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/1.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6dcb623aa5494a6f15898a0c2b06f0f7f7ff610634556d26cb2689088b08be79 +size 560564 diff --git a/EvilSatellites/sfx/physics/impacts/bullet/2.wav b/EvilSatellites/sfx/physics/impacts/bullet/2.wav new file mode 100644 index 0000000..7c9b9a0 --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/2.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1dec20679e67e66ad7d008c6bbb753f5d40ff7bf5c070cc99a283271e1ae19ca +size 797528 diff --git a/EvilSatellites/sfx/physics/impacts/bullet/3.wav b/EvilSatellites/sfx/physics/impacts/bullet/3.wav new file mode 100644 index 0000000..36c3a95 --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/3.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2fb94fe9b1fed688548b0b758ac0ff3fa3d9498312c5d7da1aec86f0b1065fb +size 556706 diff --git a/EvilSatellites/sfx/physics/impacts/bullet/4.wav b/EvilSatellites/sfx/physics/impacts/bullet/4.wav new file mode 100644 index 0000000..38bed06 --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/4.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1749b5a3d58cb1bd589d8583db1854178834e65c842ffe3204c97d4dda7b8645 +size 500204 diff --git a/EvilSatellites/sfx/physics/impacts/bullet/5.wav b/EvilSatellites/sfx/physics/impacts/bullet/5.wav new file mode 100644 index 0000000..d3e87b1 --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/5.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6b5a9b84fd7939f5769f280fae283e58255ec104915fe7d5fa591c83c2371f8 +size 488768 diff --git a/EvilSatellites/sfx/physics/impacts/bullet/6.wav b/EvilSatellites/sfx/physics/impacts/bullet/6.wav new file mode 100644 index 0000000..086487f --- /dev/null +++ b/EvilSatellites/sfx/physics/impacts/bullet/6.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59482af9289fee71dfeda1303df852713b7fc896d14df13681faa420750983aa +size 474734 diff --git a/EvilSatellites/sfx/sattelite/1/loop.wav b/EvilSatellites/sfx/sattelite/1/loop.wav new file mode 100644 index 0000000..88bf2a4 --- /dev/null +++ b/EvilSatellites/sfx/sattelite/1/loop.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73ffac2b46e73e8ffb91ff34c5495226b74567218179c1704ad41da50856fc79 +size 584784 diff --git a/EvilSatellites/sfx/weapons/LaserMG/spindown.wav b/EvilSatellites/sfx/weapons/LaserMG/spindown.wav new file mode 100644 index 0000000..c639b0b --- /dev/null +++ b/EvilSatellites/sfx/weapons/LaserMG/spindown.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98706fa6dbbb6e0abb61a8db064d2b99c567379dda060111ea244c7a6a791657 +size 149636 diff --git a/EvilSatellites/sfx/weapons/LaserMG/spinning.wav b/EvilSatellites/sfx/weapons/LaserMG/spinning.wav new file mode 100644 index 0000000..7e490e1 --- /dev/null +++ b/EvilSatellites/sfx/weapons/LaserMG/spinning.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f729f67450f4a269dcb1a174b59abb3164596fbd4dc527ebcb54ccf82edee263 +size 21212 diff --git a/EvilSatellites/sfx/weapons/LaserMG/spinup.wav b/EvilSatellites/sfx/weapons/LaserMG/spinup.wav new file mode 100644 index 0000000..3019192 --- /dev/null +++ b/EvilSatellites/sfx/weapons/LaserMG/spinup.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7edc195ba058b3213ea6b544d737e454311901fc16c5bb84741dd39981633f1 +size 159344