2
0

SoundManager.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Audio;
  8. using Microsoft.Xna.Framework.Content;
  9. namespace Asteroid_Belt_Assault
  10. {
  11. public static class SoundManager
  12. {
  13. private static List<SoundEffect> explosions = new
  14. List<SoundEffect>();
  15. private static int explosionCount = 4;
  16. private static SoundEffect playerShot;
  17. private static SoundEffect enemyShot;
  18. private static Random rand = new Random();
  19. public static void Initialize(ContentManager content)
  20. {
  21. try
  22. {
  23. playerShot = content.Load<SoundEffect>(@"Sounds\Shot1");
  24. enemyShot = content.Load<SoundEffect>(@"Sounds\Shot2");
  25. for (int x = 1; x <= explosionCount; x++)
  26. {
  27. explosions.Add(
  28. content.Load<SoundEffect>(@"Sounds\Explosion" +
  29. x.ToString()));
  30. }
  31. }
  32. catch
  33. {
  34. Debug.Write("SoundManager Initialization Failed");
  35. }
  36. }
  37. public static void PlayExplosion()
  38. {
  39. try
  40. {
  41. explosions[rand.Next(0, explosionCount)].Play();
  42. }
  43. catch
  44. {
  45. Debug.Write("PlayExplosion Failed");
  46. }
  47. }
  48. public static void PlayPlayerShot()
  49. {
  50. try
  51. {
  52. playerShot.Play();
  53. }
  54. catch
  55. {
  56. Debug.Write("PlayPlayerShot Failed");
  57. }
  58. }
  59. public static void PlayEnemyShot()
  60. {
  61. try
  62. {
  63. enemyShot.Play();
  64. }
  65. catch
  66. {
  67. Debug.Write("PlayEnemyShot Failed");
  68. }
  69. }
  70. }
  71. }