Initial spaceship

This commit is contained in:
2021-04-11 02:01:24 +02:00
parent 11ebd8db64
commit 46b1ac233b
9 changed files with 119 additions and 9 deletions
+45 -3
View File
@@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Input;
using SynthySound;
using System.Linq;
using EvilSatellites.Objects;
using DavyKager;
namespace EvilSatellites.Screens
{
@@ -15,11 +16,19 @@ namespace EvilSatellites.Screens
public ScreenState State { get; set; }
public List<IGameObject> Objects = new List<IGameObject>();
private float Theta = 0;
private Player _player;
private ISoundEffect radarNoise;
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));
Objects.Add(prop);
radarNoise = Manager.Sound.Load(@"sfx/ui/voiceError.wav", false);
radarNoise.Loop = true;
radarNoise.Play();
return;
}
@@ -28,6 +37,7 @@ namespace EvilSatellites.Screens
State = ScreenState.Hidden;
return;
}
public void Update(GameTime gameTime)
{
foreach (var obj in Objects)
@@ -35,22 +45,54 @@ namespace EvilSatellites.Screens
obj.Update(gameTime);
if (obj.Type == ObjectType.Player)
{
// obj.TranslateForward();
Manager.Sound.ListenerPosition = new System.Numerics.Vector3(obj.Position.X, obj.Position.Y, obj.Position.Z);
Manager.Sound.ListenerOrientationForward = System.Numerics.Vector3.Normalize(new System.Numerics.Vector3(obj.Rotation.Forward.X, obj.Rotation.Forward.Y, obj.Rotation.Forward.Z));
Manager.Sound.ListenerOrientationUpwards = System.Numerics.Vector3.Normalize(new System.Numerics.Vector3(obj.Rotation.Up.X, obj.Rotation.Up.Y, obj.Rotation.Up.Z));
Manager.Listener.Position = obj.Position;
Manager.Listener.Forward = obj.Rotation.Forward;
Manager.Listener.Up = obj.Rotation.Up;
// Console.WriteLine(Manager.Sound.ListenerOrientationForward);
// Console.WriteLine(Manager.Sound.ListenerOrientationUpwards);
}
}
Vector3 radarTarget = (Objects[1].Position - _player.Position);
radarTarget.Normalize();
radarNoise.Pitch = MathHelper.Clamp(0.1f / Vector3.Distance(_player.Rotation.Forward, radarTarget)*3f, 0, 1);
return;
}
public void HandleInput(GameTime gameTime, KeyboardState inputs)
{
if (inputs.IsKeyDown(Keys.W))
{
_player.Accelerate();
}
if (inputs.IsKeyDown(Keys.Left))
{
_player.RotateY(0.05f);
}
if (inputs.IsKeyDown(Keys.Right))
{
_player.RotateY(-0.05f);
}
if (inputs.IsKeyDown(Keys.Up))
{
_player.RotateX(0.05f);
}
if (inputs.IsKeyDown(Keys.Down))
{
_player.RotateX(-0.05f);
}
if (inputs.IsKeyDown(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))
{
Tolk.Speak(_player.Position.ToString());
}
}
}