OleVedeler

SoundManager

May 13th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. /*     
  2. //add to fields in game1
  3.         SoundManager soundManager;
  4. //Add to Game1 Constructer
  5.     soundManager = new SoundManager(this);
  6.     Components.Add(soundManager);    
  7. */
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using Microsoft.Xna.Framework;
  19. using Microsoft.Xna.Framework.Audio;
  20. using Microsoft.Xna.Framework.Content;
  21. using Microsoft.Xna.Framework.GamerServices;
  22. using Microsoft.Xna.Framework.Graphics;
  23. using Microsoft.Xna.Framework.Input;
  24. using Microsoft.Xna.Framework.Media;
  25.  
  26.  
  27. namespace RPGGame
  28. {
  29.     /// <summary>
  30.     /// This is a game component that implements IUpdateable.
  31.     /// </summary>
  32.     public class SoundManager : Microsoft.Xna.Framework.GameComponent
  33.     {
  34.         private AudioEngine engine;
  35.         private WaveBank waveBank;
  36.         private SoundBank soundBank;
  37.         private Cue cue;
  38.  
  39.  
  40.         public SoundManager(Game game)
  41.             : base(game)
  42.         {
  43.             engine = new AudioEngine(@"Content/Audio/GameAudio.xgs");
  44.             waveBank = new WaveBank(engine, @"Content/Audio/Wave Bank.xwb");
  45.             soundBank = new SoundBank(engine, @"Content/Audio/Sound Bank.xsb");
  46.         }
  47.  
  48.         /// <summary>
  49.         /// Allows the game component to perform any initialization it needs to before starting
  50.         /// to run.  This is where it can query for any required services and load content.
  51.         /// </summary>
  52.         public override void Initialize()
  53.         {
  54.             // TODO: Add your initialization code here
  55.             cue = soundBank.GetCue("Inception");
  56.             base.Initialize();
  57.         }
  58.  
  59.         /// <summary>
  60.         /// Allows the game component to update itself.
  61.         /// </summary>
  62.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  63.         public override void Update(GameTime gameTime)
  64.         {
  65.             engine.Update();
  66.             switch (GameState.Instance.State)
  67.             {
  68.                 case GameStateType.Meny:
  69.                     if (!cue.Name.Equals("Inception"))
  70.                         cue.Stop(AudioStopOptions.Immediate);
  71.                     if (!cue.IsPlaying)
  72.                     {
  73.                         cue = soundBank.GetCue("Inception");
  74.                         cue.Play();
  75.                     }
  76.                     break;
  77.  
  78.                 case GameStateType.inGame:
  79.                     if (!cue.Name.Equals("PartyRockAnthem"))
  80.                         cue.Stop(AudioStopOptions.Immediate);
  81.                     if (!cue.IsPlaying)
  82.                     {
  83.                         cue = soundBank.GetCue("PartyRockAnthem");
  84.                         cue.Play();
  85.                     }
  86.                     break;
  87.  
  88.                 case GameStateType.credits:
  89.                     if (!cue.Name.Equals("Morrowind"))
  90.                         cue.Stop(AudioStopOptions.Immediate);
  91.                     if (!cue.IsPlaying)
  92.                     {
  93.                         cue = soundBank.GetCue("Morrowind");
  94.                         cue.Play();
  95.                     }
  96.  
  97.                     break;
  98.  
  99.  
  100.             }
  101.  
  102.  
  103.  
  104.             base.Update(gameTime);
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment