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
+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()