diff --git a/TrueCraft.Client/AudioManager.cs b/TrueCraft.Client/AudioManager.cs new file mode 100644 index 0000000..cecfe5d --- /dev/null +++ b/TrueCraft.Client/AudioManager.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.Xna.Framework.Audio; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using TrueCraft.Core; +using Microsoft.Xna.Framework.Content; + +namespace TrueCraft.Client +{ + public class AudioManager + { + private Dictionary AudioPacks { get; set; } + + public float EffectVolume { get; set; } + public float MusicVolume { get; set; } + + public AudioManager() + { + AudioPacks = new Dictionary(); + EffectVolume = MusicVolume = 1; + } + + public void LoadDefaultPacks(ContentManager content) + { + string[][] packs = new[] + { + // TODO: step sound effects for cloth, sand, gravel, snow, wood + new[] + { + "grass", + "footstep_dirt_0.wav", + "footstep_dirt_1.wav", + "footstep_dirt_2.wav", + }, + new[] + { + "stone", + "footstep_stone_0.wav", + "footstep_stone_1.wav", + "footstep_stone_2.wav", + }, + }; + foreach (var pack in packs) + { + var name = pack[0]; + LoadAudioPack(name, pack.Skip(1).ToArray()); + } + } + + public void LoadAudioPack(string pack, string[] filenames) + { + var effects = new SoundEffect[filenames.Length]; + for (int i = 0; i < filenames.Length; i++) + { + using (var f = File.OpenRead(Path.Combine("Content", "Audio", filenames[i]))) + effects[i] = SoundEffect.FromStream(f); + } + AudioPacks[pack] = effects; + } + + public void PlayPack(string pack) + { + var i = MathHelper.Random.Next(0, AudioPacks[pack].Length); + i = 0; + AudioPacks[pack][i].Play(); + } + } +} \ No newline at end of file diff --git a/TrueCraft.Client/Content/Audio/credits.txt b/TrueCraft.Client/Content/Audio/credits.txt new file mode 100644 index 0000000..e7f5994 --- /dev/null +++ b/TrueCraft.Client/Content/Audio/credits.txt @@ -0,0 +1,4 @@ +Dirt and Stone footsteps CC-BY-SA from http://www.littlerobotsoundfactory.com/ +Snow footsteps CC-BY-SA & public domain from http://freesound.org/people/iujhu/ +Wood footsteps CC-BY-SA from http://www.ronaldvanwonderen.com/ and http://freesound.org/people/wildweasel/ +Cloth footsteps CC-0/public domain from http://freesound.org/people/Yuval/ \ No newline at end of file diff --git a/TrueCraft.Client/Content/Audio/footstep_dirt_0.wav b/TrueCraft.Client/Content/Audio/footstep_dirt_0.wav new file mode 100644 index 0000000..98f4736 Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_dirt_0.wav differ diff --git a/TrueCraft.Client/Content/Audio/footstep_dirt_1.wav b/TrueCraft.Client/Content/Audio/footstep_dirt_1.wav new file mode 100644 index 0000000..bd47ccf Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_dirt_1.wav differ diff --git a/TrueCraft.Client/Content/Audio/footstep_dirt_2.wav b/TrueCraft.Client/Content/Audio/footstep_dirt_2.wav new file mode 100644 index 0000000..cb5c2b0 Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_dirt_2.wav differ diff --git a/TrueCraft.Client/Content/Audio/footstep_stone_0.wav b/TrueCraft.Client/Content/Audio/footstep_stone_0.wav new file mode 100644 index 0000000..cd897ae Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_stone_0.wav differ diff --git a/TrueCraft.Client/Content/Audio/footstep_stone_1.wav b/TrueCraft.Client/Content/Audio/footstep_stone_1.wav new file mode 100644 index 0000000..cb5c2b0 Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_stone_1.wav differ diff --git a/TrueCraft.Client/Content/Audio/footstep_stone_2.wav b/TrueCraft.Client/Content/Audio/footstep_stone_2.wav new file mode 100644 index 0000000..94f6637 Binary files /dev/null and b/TrueCraft.Client/Content/Audio/footstep_stone_2.wav differ diff --git a/TrueCraft.Client/Modules/PlayerControlModule.cs b/TrueCraft.Client/Modules/PlayerControlModule.cs index 793d2af..2dd0bc5 100644 --- a/TrueCraft.Client/Modules/PlayerControlModule.cs +++ b/TrueCraft.Client/Modules/PlayerControlModule.cs @@ -334,6 +334,9 @@ namespace TrueCraft.Client.Modules Game.Bobbing += Math.Max(Math.Abs(lookAt.X), Math.Abs(lookAt.Z)); Game.Client.Velocity = new TVector3(lookAt.X, Game.Client.Velocity.Y, lookAt.Z); + + if ((int)Game.Bobbing % 2 == 0) + Game.Audio.PlayPack("grass"); } else Game.Client.Velocity *= new TVector3(0, 1, 0); diff --git a/TrueCraft.Client/TrueCraft.Client.csproj b/TrueCraft.Client/TrueCraft.Client.csproj index eba8afb..b0ff619 100644 --- a/TrueCraft.Client/TrueCraft.Client.csproj +++ b/TrueCraft.Client/TrueCraft.Client.csproj @@ -141,6 +141,7 @@ + @@ -242,8 +243,30 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + \ No newline at end of file diff --git a/TrueCraft.Client/TrueCraftGame.cs b/TrueCraft.Client/TrueCraftGame.cs index d78c2e2..ba1a8ca 100644 --- a/TrueCraft.Client/TrueCraftGame.cs +++ b/TrueCraft.Client/TrueCraftGame.cs @@ -38,6 +38,7 @@ namespace TrueCraft.Client public DateTime StartDigging { get; set; } public DateTime EndDigging { get; set; } public Coordinates3D TargetBlock { get; set; } + public AudioManager Audio { get; set; } private List Modules { get; set; } private SpriteBatch SpriteBatch { get; set; } @@ -115,6 +116,9 @@ namespace TrueCraft.Client base.Initialize(); // (calls LoadContent) + Audio = new AudioManager(); + Audio.LoadDefaultPacks(Content); + ChunkModule = new ChunkModule(this); DebugInfoModule = new DebugInfoModule(this, Pixel);