Initial music impl

This commit is contained in:
2021-04-23 20:28:06 +02:00
parent 44f0f9e399
commit 1aa7a57d91
19 changed files with 171 additions and 7 deletions
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -32,13 +32,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="CppSharp.Runtime"> <Reference Include="CppSharp.Runtime">
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\CppSharp.Runtime.dll</HintPath> <HintPath>..\..\synthy\Synthy\bin\Release\netstandard2.1\CppSharp.Runtime.dll</HintPath>
</Reference> </Reference>
<Reference Include="Synthizer.Net"> <Reference Include="Synthizer.Net">
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\Synthizer.Net.dll</HintPath> <HintPath>..\..\synthy\Synthy\bin\Release\netstandard2.1\Synthizer.Net.dll</HintPath>
</Reference> </Reference>
<Reference Include="Synthy"> <Reference Include="Synthy">
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\Synthy.dll</HintPath> <HintPath>..\..\synthy\Synthy\bin\Release\netstandard2.1\Synthy.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
</Project> </Project>
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EvilSatellites
{
public static class GameStats
{
public static int ShotsFired;
public static int SatellitesShot;
public static int DebrisCollected;
public static int SatelliteCollisions;
public static int DebrisCollisions;
public static double TotalPlayTime;
public static void Reset()
{
ShotsFired = 0;
SatellitesShot = 0;
DebrisCollected = 0;
SatelliteCollisions = 0;
DebrisCollisions = 0;
TotalPlayTime = 0;
}
}
}
+59
View File
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SynthySound;
namespace EvilSatellites
{
public class MusicManager
{
public ISoundEffect Song;
public float _Volume;
public float Volume {
get => _Volume;
set
{
if (IsPlaying)
{
Song.Volume = Volume;
}
_Volume = Volume;
}
}
public bool IsPlaying;
public Synthy Engine;
public MusicManager(Synthy engine)
{
Engine = engine;
_Volume = 0.2f;
IsPlaying = false;
}
public void Play(string path)
{
if (IsPlaying)
{
Song.Stop();
Song.Destroy();
}
Song = Engine.Load(@"sfx/music/" + path + ".mp3", false, true);
Song.Play();
Song.Volume = _Volume;
Song.Loop = true;
IsPlaying = true;
}
public void Stop()
{
if (IsPlaying)
{
Song.Stop();
Song.Destroy();
IsPlaying = false;
}
}
}
}
+2
View File
@@ -58,10 +58,12 @@ namespace EvilSatellites.Objects
{ {
player.CurrentWeapon.Reload(rnd.Next(player.CurrentWeapon.MaxAmmo/4)); player.CurrentWeapon.Reload(rnd.Next(player.CurrentWeapon.MaxAmmo/4));
Destroy(); Destroy();
GameStats.DebrisCollected++;
return; return;
} }
player.TakeDamage(25); player.TakeDamage(25);
Destroy(); Destroy();
GameStats.SatelliteCollisions++;
} }
} }
} }
+2 -2
View File
@@ -207,8 +207,8 @@ namespace EvilSatellites.Objects
{ {
Destroy(); Destroy();
Screen.Manager.Sound.PlayOneshot(@"sfx/physics/crashes/1.wav"); Screen.Manager.Sound.PlayOneshot(@"sfx/physics/crashes/1.wav");
System.Threading.Thread.Sleep(2000); var scr = (GameScreen)Screen;
Environment.Exit(0); scr.EndGame();
} }
} }
+1
View File
@@ -83,6 +83,7 @@ namespace EvilSatellites.Objects
Screen.Manager.Sound.PlayOneshot(@"sfx/satellite/"+SatelliteID.ToString()+"/explode.wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z)); Screen.Manager.Sound.PlayOneshot(@"sfx/satellite/"+SatelliteID.ToString()+"/explode.wav", new System.Numerics.Vector3(Position.X, Position.Y, Position.Z));
SpawnDebris(); SpawnDebris();
Destroy(); Destroy();
GameStats.SatellitesShot++;
} }
} }
+4
View File
@@ -122,5 +122,9 @@ namespace EvilSatellites
} }
} }
public void Destroy()
{
RadarNoise.Destroy();
}
} }
} }
+5
View File
@@ -43,5 +43,10 @@ namespace EvilSatellites
Spawn(); Spawn();
} }
} }
public void Destroy()
{
return;
}
} }
} }
+4 -2
View File
@@ -18,12 +18,14 @@ namespace EvilSatellites
private IScreen _CurrentScreen; private IScreen _CurrentScreen;
private Game _Game; private Game _Game;
private bool _Running = false; private bool _Running = false;
public Synthy Sound = new Synthy(); public Synthy Sound;
public MusicManager Music;
public FDNReverb EnvironmentEffect; public FDNReverb EnvironmentEffect;
public AudioListener Listener = new AudioListener(); public AudioListener Listener = new AudioListener();
public ScreenManager(Game instance): base(instance) public ScreenManager(Game instance): base(instance)
{ {
Sound = new Synthy();
Music = new MusicManager(Sound);
EnvironmentEffect = Sound.CreateReverb(); EnvironmentEffect = Sound.CreateReverb();
EnvironmentEffect.Delay = 0.03; EnvironmentEffect.Delay = 0.03;
EnvironmentEffect.Wet = 30; EnvironmentEffect.Wet = 30;
+28
View File
@@ -24,6 +24,7 @@ namespace EvilSatellites.Screens
private Player _player; private Player _player;
private Radar ObjectRadar; private Radar ObjectRadar;
private SatelliteSpawner Spawner; private SatelliteSpawner Spawner;
private bool GameOver = false;
public void Activate() public void Activate()
{ {
State = ScreenState.Active; State = ScreenState.Active;
@@ -33,6 +34,8 @@ namespace EvilSatellites.Screens
ObjectRadar = new Radar(_player, this); ObjectRadar = new Radar(_player, this);
Spawner = new SatelliteSpawner(this); Spawner = new SatelliteSpawner(this);
Spawner.Spawn(); Spawner.Spawn();
GameStats.Reset();
Manager.Music.Play("game1");
return; return;
} }
@@ -44,6 +47,19 @@ namespace EvilSatellites.Screens
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
{ {
if (GameOver == true)
{
foreach (var obj in Objects)
{
obj.Destroy();
}
ObjectRadar.Destroy();
Spawner.Destroy();
// TODO: figure out why cleanup doesn't work
// Manager.Sound.Cleanup();
HandleGameOver(gameTime);
}
foreach (var obj in Removable) foreach (var obj in Removable)
{ {
Objects.Remove(obj); Objects.Remove(obj);
@@ -241,5 +257,17 @@ namespace EvilSatellites.Screens
{ {
return _player; return _player;
} }
public void HandleGameOver(GameTime time)
{
GameStats.TotalPlayTime = time.TotalGameTime.TotalSeconds;
Manager.RemoveScreen(this);
Manager.AddScreen(new StatsScreen());
}
public void EndGame()
{
GameOver = true;
}
} }
} }
+1
View File
@@ -29,6 +29,7 @@ namespace EvilSatellites.Screens
Tolk.Output(MenuOptions.Description, false); Tolk.Output(MenuOptions.Description, false);
Tolk.Output(MenuOptions.Entries[CursorPosition].Name); Tolk.Output(MenuOptions.Entries[CursorPosition].Name);
Manager.Sound.PlayOneshot(@"sfx/ui/menuOpen.wav"); Manager.Sound.PlayOneshot(@"sfx/ui/menuOpen.wav");
Manager.Music.Play("menu1");
} }
public virtual void Deactivate() public virtual void Deactivate()
+33
View File
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvilSatellites.Screens;
using EvilSatellites.Menu;
namespace EvilSatellites.Screens
{
public class StatsScreen : MenuScreen
{
public override void Activate()
{
MenuOptions = new MenuContainer("Statistics", "Statistics for current game");
MenuOptions.Add(new MenuEntry("Shots fired: " + GameStats.ShotsFired.ToString(), "Amount of shots fired during this game."))
.Add(new MenuEntry("Satellites shot: " + GameStats.SatellitesShot.ToString(), "Amount of satellites shot during this game."))
.Add(new MenuEntry("Debris collected: " + GameStats.DebrisCollected.ToString(), "Amount of debris collected during this game."))
.Add(new MenuEntry("Satellite collisions: " + GameStats.SatelliteCollisions.ToString(), "How many satellites you crashed into"))
.Add(new MenuEntry("Total play time: " + GameStats.TotalPlayTime.ToString(), "How much time you spent on this run"))
.Add(new MenuEntry("OK", "Go back to main menu"));
}
public override void SelectItem()
{
if (CursorPosition == MenuOptions.Entries.Count-1)
{
Manager.RemoveScreen(this);
Manager.AddScreen(new MainMenuScreen());
}
}
}
}
+1
View File
@@ -94,6 +94,7 @@ namespace EvilSatellites.Weapons
TimerStart = TimerEnd; TimerStart = TimerEnd;
Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation, _wielder); Projectile proj = new Projectile(Screen, _wielder.Position, _wielder.Rotation, _wielder);
Screen.AddObject(proj); Screen.AddObject(proj);
GameStats.ShotsFired++;
} else } else
{ {
sfxEmpty.Reset(); sfxEmpty.Reset();
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.