Add turning and elevator sounds

This commit is contained in:
2021-04-18 22:35:49 +02:00
parent cc3df2e2a5
commit 3d9ca3d590
4 changed files with 68 additions and 8 deletions
Binary file not shown.
Binary file not shown.
+52
View File
@@ -16,7 +16,12 @@ namespace EvilSatellites.Objects
private Vector3 Deceleration = new Vector3(0.0025f, 0.0025f, 0.0025f); private Vector3 Deceleration = new Vector3(0.0025f, 0.0025f, 0.0025f);
private ISoundEffect sfxEngine; private ISoundEffect sfxEngine;
private ISoundEffect sfxWhine; private ISoundEffect sfxWhine;
private SoundPatch sfxElevator;
private SoundPatch sfxVacuum;
private SoundPatch sfxTurn;
public IWeapon CurrentWeapon; public IWeapon CurrentWeapon;
private int Turning;
private int Elevating;
public Player(IScreen screen): base(screen) public Player(IScreen screen): base(screen)
{ {
ShouldDestroy = false; ShouldDestroy = false;
@@ -28,6 +33,7 @@ namespace EvilSatellites.Objects
Rotation = Matrix.Identity; Rotation = Matrix.Identity;
Orientation = Rotation.Forward; Orientation = Rotation.Forward;
CurrentWeapon = new LaserMG(this, (GameScreen)Screen); CurrentWeapon = new LaserMG(this, (GameScreen)Screen);
Turning = 0;
Activate(); Activate();
} }
@@ -35,6 +41,9 @@ namespace EvilSatellites.Objects
{ {
sfxEngine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineThrust.wav", false); sfxEngine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineThrust.wav", false);
sfxWhine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineWhine.wav", false); sfxWhine = Screen.Manager.Sound.Load(@"sfx/engine/int/engineWhine.wav", false);
sfxTurn = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/turn", 200);
sfxVacuum = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/vacuum", 500);
sfxElevator = new SoundPatch(Screen.Manager.Sound, @"sfx/ship/elevator", 250);
sfxEngine.Loop = true; sfxEngine.Loop = true;
sfxWhine.Loop = true; sfxWhine.Loop = true;
sfxEngine.ConnectToEffect(Screen.Manager.EnvironmentEffect); sfxEngine.ConnectToEffect(Screen.Manager.EnvironmentEffect);
@@ -54,9 +63,28 @@ namespace EvilSatellites.Objects
{ {
CurrentWeapon.Update(gameTime); CurrentWeapon.Update(gameTime);
Move(Movement); Move(Movement);
if (Turning == -1)
{
RotateY(0.035f);
}
if (Turning == 1)
{
RotateY(-0.035f);
}
if (Elevating == -1)
{
RotateX(-0.035f);
}
if (Elevating == 1)
{
RotateX(0.035f);
}
sfxEngine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 4; sfxEngine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 4;
sfxWhine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 1; sfxWhine.Pitch = 0.5 + (Movement.Length() / MaxSpeed.Length()) * 1;
sfxWhine.Volume = MathF.Pow(Movement.Length() / MaxSpeed.Length(), 2f); sfxWhine.Volume = MathF.Pow(Movement.Length() / MaxSpeed.Length(), 2f);
sfxTurn.Update(gameTime);
sfxElevator.Update(gameTime);
sfxVacuum.Update(gameTime);
if (Movement.Length() != 0) if (Movement.Length() != 0)
{ {
if (Movement.X > 0) if (Movement.X > 0)
@@ -92,5 +120,29 @@ namespace EvilSatellites.Objects
Movement += direction; Movement += direction;
} }
} }
public void StartTurning(int dir, GameTime time)
{
Turning = dir;
sfxTurn.Start(time);
}
public void StopTurning()
{
Turning = 0;
sfxTurn.Stop();
}
public void StartElevating(int dir, GameTime time)
{
Elevating = dir;
sfxElevator.Start(time);
}
public void StopElevating()
{
Elevating = 0;
sfxElevator.Stop();
}
} }
} }
+16 -8
View File
@@ -106,21 +106,29 @@ namespace EvilSatellites.Screens
{ {
move.X = _player.Acceleration.X; move.X = _player.Acceleration.X;
} }
if (Input.IsPressed(Keys.Left)) if (Input.IsJustPressed(Keys.Left))
{ {
_player.RotateY(0.05f); _player.StartTurning(-1, gameTime);
} }
if (Input.IsPressed(Keys.Right)) if (Input.IsJustPressed(Keys.Right))
{ {
_player.RotateY(-0.05f); _player.StartTurning(1, gameTime);
} }
if (Input.IsPressed(Keys.Up)) if (Input.IsJustReleased(Keys.Left) || Input.IsJustReleased(Keys.Right))
{ {
_player.RotateX(0.05f); _player.StopTurning();
} }
if (Input.IsPressed(Keys.Down)) if (Input.IsJustPressed(Keys.Up))
{ {
_player.RotateX(-0.05f); _player.StartElevating(-1, gameTime);
}
if (Input.IsJustPressed(Keys.Down))
{
_player.StartElevating(1, gameTime);
}
if (Input.IsJustReleased(Keys.Up) || Input.IsJustReleased(Keys.Down))
{
_player.StopElevating();
} }
_player.Accelerate(move); _player.Accelerate(move);
if (Input.IsJustPressed(Keys.Space)) if (Input.IsJustPressed(Keys.Space))