This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundManager.cs
60 lines (53 loc) · 1.97 KB
/
SoundManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//-----------------------------------------------------------------------------
// SoundManager maintains a list of cues and their corresponding files.
// This is a very bare bones way to play sound files.
//
// __Defense Sample for Game Programming Algorithms and Techniques
// Copyright (C) Sanjay Madhav. All rights reserved.
//
// Released under the Microsoft Permissive License.
// See LICENSE.txt for full details.
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Content;
namespace itp380
{
public class SoundManager : Patterns.Singleton<SoundManager>
{
Dictionary<string, SoundEffect> m_Sounds = new Dictionary<string, SoundEffect>();
Song backgroundMusic;
public SoundManager()
{
}
// Load the SFX
public void LoadContent(ContentManager Content)
{
m_Sounds.Add("Shoot", Content.Load<SoundEffect>("Sounds/Shoot"));
m_Sounds.Add("MenuClick", Content.Load<SoundEffect>("Sounds/MenuClick"));
m_Sounds.Add("Build", Content.Load<SoundEffect>("Sounds/Build"));
m_Sounds.Add("GameOver", Content.Load<SoundEffect>("Sounds/GameOver"));
m_Sounds.Add("Victory", Content.Load<SoundEffect>("Sounds/Victory"));
m_Sounds.Add("Error", Content.Load<SoundEffect>("Sounds/Error"));
m_Sounds.Add("Snared", Content.Load<SoundEffect>("Sounds/Snared"));
m_Sounds.Add("Alarm", Content.Load<SoundEffect>("Sounds/Alarm"));
backgroundMusic = Content.Load<Song>("Sounds/Peacemaker");
PlayBackgroundMusic();
// TODO: Add any additional sounds here
}
public void PlaySoundCue(string cue)
{
m_Sounds[cue].Play();
}
public void PlayBackgroundMusic()
{
MediaPlayer.Volume = 0.5f;
MediaPlayer.IsRepeating = true;
MediaPlayer.Play(backgroundMusic);
}
}
}