GhostSoundsManager.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework.Audio;
  4. using Microsoft.Xna.Framework;
  5. namespace XNAPacMan {
  6. /// <summary>
  7. /// All four ghosts use the same sounds, and only one can be played at a time. So, instead of having to
  8. /// synchronize each other, they use this class.
  9. /// </summary>
  10. static class GhostSoundsManager {
  11. static public void Init(Game game) {
  12. soundBank_ = (SoundBank)game.Services.GetService(typeof(SoundBank));
  13. InitCues();
  14. }
  15. static public void playLoopAttack() {
  16. playLoop(ref loopAttack_);
  17. }
  18. static public void playLoopAttackFast() {
  19. playLoop(ref loopAttackFast_);
  20. }
  21. static public void playLoopAttackVeryFast() {
  22. playLoop(ref loopAttackVeryFast_);
  23. }
  24. static public void playLoopBlue() {
  25. playLoop(ref loopBlue_);
  26. }
  27. static public void playLoopDead() {
  28. playLoop(ref loopDead_);
  29. }
  30. static void playLoop(ref Cue cue) {
  31. if (!cue.IsPlaying) {
  32. StopLoops();
  33. InitCues();
  34. cue.Play();
  35. }
  36. }
  37. static void InitCues() {
  38. loopAttack_ = soundBank_.GetCue("GhostNormalLoop1");
  39. loopAttackFast_ = soundBank_.GetCue("GhostFastLoop");
  40. loopAttackVeryFast_ = soundBank_.GetCue("GhostVFastLoop");
  41. loopDead_ = soundBank_.GetCue("GhostRunningHome");
  42. loopBlue_ = soundBank_.GetCue("GhostChased");
  43. }
  44. static public void StopLoops() {
  45. loopAttack_.Stop(AudioStopOptions.AsAuthored);
  46. loopAttackFast_.Stop(AudioStopOptions.AsAuthored);
  47. loopAttackVeryFast_.Stop(AudioStopOptions.AsAuthored);
  48. loopDead_.Stop(AudioStopOptions.AsAuthored);
  49. loopBlue_.Stop(AudioStopOptions.AsAuthored);
  50. }
  51. static public void PauseLoops() {
  52. loopAttack_.Pause();
  53. loopAttackFast_.Pause();
  54. loopAttackVeryFast_.Pause();
  55. loopDead_.Pause();
  56. loopBlue_.Pause();
  57. }
  58. static public void ResumeLoops() {
  59. loopAttack_.Resume();
  60. loopAttackFast_.Resume();
  61. loopAttackVeryFast_.Resume();
  62. loopDead_.Resume();
  63. loopBlue_.Resume();
  64. }
  65. static SoundBank soundBank_;
  66. static Cue loopAttack_;
  67. static Cue loopAttackFast_;
  68. static Cue loopAttackVeryFast_;
  69. static Cue loopBlue_;
  70. static Cue loopDead_;
  71. }
  72. }