Initial pass on sound effects on client

Broken due to MonoGame problems
This commit is contained in:
Drew DeVault 2015-10-04 10:06:44 -04:00
parent 6bfa813d54
commit 8f6e577550
11 changed files with 103 additions and 0 deletions

View File

@ -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<string, SoundEffect[]> AudioPacks { get; set; }
public float EffectVolume { get; set; }
public float MusicVolume { get; set; }
public AudioManager()
{
AudioPacks = new Dictionary<string, SoundEffect[]>();
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();
}
}
}

View File

@ -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/

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -334,6 +334,9 @@ namespace TrueCraft.Client.Modules
Game.Bobbing += Math.Max(Math.Abs(lookAt.X), Math.Abs(lookAt.Z)); 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); Game.Client.Velocity = new TVector3(lookAt.X, Game.Client.Velocity.Y, lookAt.Z);
if ((int)Game.Bobbing % 2 == 0)
Game.Audio.PlayPack("grass");
} }
else else
Game.Client.Velocity *= new TVector3(0, 1, 0); Game.Client.Velocity *= new TVector3(0, 1, 0);

View File

@ -141,6 +141,7 @@
<Compile Include="Input\GamePadHandler.cs" /> <Compile Include="Input\GamePadHandler.cs" />
<Compile Include="Input\GamePadEventArgs.cs" /> <Compile Include="Input\GamePadEventArgs.cs" />
<Compile Include="Input\GamePadButtonEventArgs.cs" /> <Compile Include="Input\GamePadButtonEventArgs.cs" />
<Compile Include="AudioManager.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
@ -242,8 +243,30 @@
<Content Include="Content\icons.png"> <Content Include="Content\icons.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Audio\credits.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_dirt_0.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_dirt_1.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_dirt_2.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_stone_0.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_stone_1.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Audio\footstep_stone_2.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Modules\" /> <Folder Include="Modules\" />
<Folder Include="Content\Audio\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -38,6 +38,7 @@ namespace TrueCraft.Client
public DateTime StartDigging { get; set; } public DateTime StartDigging { get; set; }
public DateTime EndDigging { get; set; } public DateTime EndDigging { get; set; }
public Coordinates3D TargetBlock { get; set; } public Coordinates3D TargetBlock { get; set; }
public AudioManager Audio { get; set; }
private List<IGameplayModule> Modules { get; set; } private List<IGameplayModule> Modules { get; set; }
private SpriteBatch SpriteBatch { get; set; } private SpriteBatch SpriteBatch { get; set; }
@ -115,6 +116,9 @@ namespace TrueCraft.Client
base.Initialize(); // (calls LoadContent) base.Initialize(); // (calls LoadContent)
Audio = new AudioManager();
Audio.LoadDefaultPacks(Content);
ChunkModule = new ChunkModule(this); ChunkModule = new ChunkModule(this);
DebugInfoModule = new DebugInfoModule(this, Pixel); DebugInfoModule = new DebugInfoModule(this, Pixel);