Add basic radar and weapon

This commit is contained in:
2021-04-11 17:09:57 +02:00
parent 1c2fc7b86b
commit 2f7759d190
26 changed files with 465 additions and 45 deletions
+6 -21
View File
@@ -9,31 +9,17 @@ namespace EvilSatellites
{
public class AudioAsset
{
private List<ISoundEffect3D> _SoundList { get; set; }
private List<ISoundEffect> _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<ISoundEffect3D>();
IsPanning = panning;
_SoundList = new List<ISoundEffect>();
_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));
}
}
+85
View File
@@ -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<ISoundEffect3D> _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<ISoundEffect3D>();
_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();
}
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0</TargetFramework>
+47
View File
@@ -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);
}
}
}
@@ -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
{
+5
View File
@@ -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;
+45
View File
@@ -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();
}
}
}
+1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using SynthySound;
using EvilSatellites.Screens;
namespace EvilSatellites.Objects
{
+60
View File
@@ -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<IGameObject> 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);
}
}
}
+2
View File
@@ -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
{
+40 -22
View File
@@ -15,22 +15,21 @@ namespace EvilSatellites.Screens
{
public ScreenManager Manager { get; set; }
public ScreenState State { get; set; }
private InputManager Input = new InputManager();
public List<IGameObject> Objects = new List<IGameObject>();
private Quadtree<IGameObject> objtree = new Quadtree<IGameObject>(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()
@@ -4,7 +4,7 @@ using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace EvilSatellites
namespace EvilSatellites.Screens
{
public interface IScreen
{
+34
View File
@@ -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) { }
}
}
+22
View File
@@ -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; }
}
}
+85
View File
@@ -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);
}
}
}
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6dcb623aa5494a6f15898a0c2b06f0f7f7ff610634556d26cb2689088b08be79
size 560564
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1dec20679e67e66ad7d008c6bbb753f5d40ff7bf5c070cc99a283271e1ae19ca
size 797528
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a2fb94fe9b1fed688548b0b758ac0ff3fa3d9498312c5d7da1aec86f0b1065fb
size 556706
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1749b5a3d58cb1bd589d8583db1854178834e65c842ffe3204c97d4dda7b8645
size 500204
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e6b5a9b84fd7939f5769f280fae283e58255ec104915fe7d5fa591c83c2371f8
size 488768
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:59482af9289fee71dfeda1303df852713b7fc896d14df13681faa420750983aa
size 474734
+3
View File
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:73ffac2b46e73e8ffb91ff34c5495226b74567218179c1704ad41da50856fc79
size 584784
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:98706fa6dbbb6e0abb61a8db064d2b99c567379dda060111ea244c7a6a791657
size 149636
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f729f67450f4a269dcb1a174b59abb3164596fbd4dc527ebcb54ccf82edee263
size 21212
@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e7edc195ba058b3213ea6b544d737e454311901fc16c5bb84741dd39981633f1
size 159344