#region File Description
//-----------------------------------------------------------------------------
// Sound.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework.Audio;
#endregion
namespace Spacewar
{
///
/// An enum for all of the spaceWar sounds
///
public enum Sounds
{
///
/// Peashoot gun shot sound
///
PeashooterFire,
///
/// Entering hyperspace
///
HyperspaceActivate,
///
/// Returning from hyperspace
///
HyperspaceReturn,
///
/// Rocket weapon sound
///
RocketFire,
///
/// Rocket weapon final explosion sound
///
RocketExplode,
///
/// BFG weapon sound
///
BFGFire,
///
/// Menu Selection Sound
///
MenuSelect,
///
/// Menu Advance sound
///
MenuAdvance,
///
/// Menu Back Sound
///
MenuBack,
///
/// Bad Menu selection Sound
///
MenuBadSelect,
///
/// Menu Scroll sound
///
MenuScroll,
///
/// Alternate Menu selection sound
///
MenuSelect2,
///
/// Another Alternate Menu selection Sound
///
MenuSelect3,
///
/// Bonus weapon pickup sound
///
WeaponPickup,
///
/// Timer expiry sound
///
CountDownExpire,
///
/// Beep sound for last few seconds of a countdown
///
CountDownWarning,
///
/// Phase Activation sound
///
PhaseActivate,
///
/// Phase Expiration sound
///
PhaseExpire,
///
/// Engine sound for player1
///
ThrustPlayer1,
///
/// Engine sound for player2
///
ThrustPlayer2,
///
/// Title screen music
///
TitleMusic,
///
/// Ambient music for menu backgrounds
///
MenuMusic,
///
/// Counter when points or money ar tallying
///
PointsTally,
///
/// General explosion
///
Explosion,
///
/// Machine gun weapon sound
///
MachineGunFire,
///
/// Double machine gun weapon sound
///
DoubleMachineGunFire,
///
/// BFG Explosion sound
///
BFGExplode,
///
/// When ship is damaged
///
DamageShip,
///
/// When ship is destroyed
///
ExplodeShip,
}
///
/// Abstracts away the sounds for a simple interface using the Sounds enum
///
public static class Sound
{
private static AudioEngine engine;
private static WaveBank wavebank;
private static SoundBank soundbank;
private static string[] cueNames = new string[]
{
"tx0_fire", //
"hyperspace_activate", //
"hyperspace_return", //
"pdp3_fire",
"pdp3_explode",
"hax2_fire",
"menu_select",
"menu_advance", //Used all over - probbly need to choose where is back/select/advance etc
"menu_back",
"menu_bad_select",
"menu_scroll",
"menu_select2",
"menu_select3",
"weapon_pickup",
"countdown_expire", //
"countdown_warning", //
"phase_activate",
"phase_expire",
"accel_player1", //
"accel_player2", //
"title_music", //sort of - not working!
"menu_music", //sort of - not working
"points_tally", //used on cash right now
"explosion_generic",
"pdp1_fire",
"pdp2_fire",
"hax2_impact",
"damage_ship",
"explosion_ship",
};
///
/// Plays a sound
///
/// Which sound to play
/// XACT cue to be used if you want to stop this particular looped sound. Can NOT be ignored. If the cue returned goes out of scope, the sound stops!!
public static Cue Play(Sounds sound)
{
Cue returnValue = soundbank.GetCue(cueNames[(int)sound]);
returnValue.Play();
return returnValue;
}
///
/// Plays a sound
///
/// Which sound to play
/// Nothing! This cue will play through to completion and then free itself.
public static void PlayCue(Sounds sound)
{
soundbank.PlayCue(cueNames[(int)sound]);
}
///
/// Pumps the AudioEngine to help it clean itself up
///
public static void Update()
{
engine.Update();
}
///
/// Stops a previously playing cue
///
/// The cue to stop that you got returned from Play(sound)
public static void Stop(Cue cue)
{
cue.Stop(AudioStopOptions.Immediate);
}
///
/// Starts up the sound code
///
public static void Initialize()
{
engine = new AudioEngine(SpacewarGame.Settings.MediaPath + @"audio\spacewar.xgs");
wavebank = new WaveBank(engine, SpacewarGame.Settings.MediaPath + @"audio\spacewar.xwb");
soundbank = new SoundBank(engine, SpacewarGame.Settings.MediaPath + @"audio\spacewar.xsb");
}
///
/// Shuts down the sound code tidily
///
public static void Shutdown()
{
soundbank.Dispose();
wavebank.Dispose();
engine.Dispose();
}
}
}