Initial pass on sound effects on client
Broken due to MonoGame problems
This commit is contained in:
parent
6bfa813d54
commit
8f6e577550
69
TrueCraft.Client/AudioManager.cs
Normal file
69
TrueCraft.Client/AudioManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
4
TrueCraft.Client/Content/Audio/credits.txt
Normal file
4
TrueCraft.Client/Content/Audio/credits.txt
Normal 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/
|
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_0.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_0.wav
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_1.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_1.wav
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_2.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_dirt_2.wav
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/footstep_stone_0.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_stone_0.wav
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/footstep_stone_1.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_stone_1.wav
Normal file
Binary file not shown.
BIN
TrueCraft.Client/Content/Audio/footstep_stone_2.wav
Normal file
BIN
TrueCraft.Client/Content/Audio/footstep_stone_2.wav
Normal file
Binary file not shown.
@ -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);
|
||||
|
@ -141,6 +141,7 @@
|
||||
<Compile Include="Input\GamePadHandler.cs" />
|
||||
<Compile Include="Input\GamePadEventArgs.cs" />
|
||||
<Compile Include="Input\GamePadButtonEventArgs.cs" />
|
||||
<Compile Include="AudioManager.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
@ -242,8 +243,30 @@
|
||||
<Content Include="Content\icons.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</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>
|
||||
<Folder Include="Modules\" />
|
||||
<Folder Include="Content\Audio\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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<IGameplayModule> 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);
|
||||
|
||||
|
Reference in New Issue
Block a user