1. #include "SDL/SDL.h"
  2. #include "SDL/SDL_mixer.h"
  3. #include "CPSound.h"
  4.  
  5. //Load functions for weapon sound effects
  6. weapon_fire::weapon_fire()
  7. {
  8.     fireB = NULL;
  9.     fireC = NULL;
  10.     fireL = NULL;
  11.     fireM = NULL;
  12.      fireP = NULL;
  13. }
  14. weapon_fire::~weapon_fire()
  15. {
  16.     Mix_FreeChunk(fireB);
  17.     Mix_FreeChunk(fireC);
  18.     Mix_FreeChunk(fireL);
  19.     Mix_FreeChunk(fireM);
  20.      Mix_FreeChunk(fireP);
  21. }
  22.  
  23. bool weapon_fire::setup()
  24. {
  25.     fireB = Mix_LoadWAV("./Media/Sound/blaster.wav");
  26.     fireC = Mix_LoadWAV("./Media/Sound/cannon.wav");
  27.     fireL = Mix_LoadWAV("./Media/Sound/laser.wav");
  28.     fireM = Mix_LoadWAV("./Media/Sound/missile.wav");
  29.     fireP = Mix_LoadWAV("./Media/Sound/plasma.wav");
  30.     if (fireB == NULL || fireC == NULL || fireL == NULL | fireM == NULL | fireP == NULL)
  31.         return false;
  32.  
  33.     return true;
  34. }
  35.  
  36. void weapon_fire::blaster()
  37. {
  38.     Mix_PlayChannel(-1, fireB, 0);
  39. }
  40.  
  41. void weapon_fire::cannon()
  42. {
  43.     Mix_PlayChannel(-1, fireC, 0);
  44. }
  45.  
  46. void weapon_fire::laser()
  47. {
  48.     Mix_PlayChannel(-1, fireL, 0);
  49. }
  50.  
  51. void weapon_fire::missile()
  52. {
  53.     Mix_PlayChannel(-1, fireM, 0);
  54. }
  55.  
  56. void weapon_fire::plasma()
  57. {
  58.     Mix_PlayChannel(-1, fireP, 0);
  59. }
  60.  
  61. //Load background or environment effects
  62. environment::environment()
  63. {
  64.     music = NULL;
  65.     boom  = NULL;
  66.     tele  = NULL;
  67. }
  68. environment::~environment()
  69. {
  70.     Mix_FreeMusic(music);
  71.     Mix_FreeChunk(boom);
  72.     Mix_FreeChunk(tele);
  73. }
  74.  
  75. bool environment::setup()
  76. {
  77.     music = Mix_LoadMUS("./Media/Sound/Music/Plunder_the_Galaxy.wav"); // trance_industrial_raw_mix.wav");  
  78.     boom = Mix_LoadWAV("./Media/Sound/explosion.wav");
  79.     tele = Mix_LoadWAV("./Media/Sound/teleport_activate.wav");
  80.      if (music == NULL || boom == NULL || tele == NULL)
  81.           return false;
  82.      return true;
  83. }
  84. void environment::background_music()
  85. {
  86.     Mix_PlayMusic(music, -1);
  87. }
  88.  
  89. void environment::explosion()
  90. {
  91.     Mix_PlayChannel(-1, boom, 0);
  92. }
  93.  
  94. void environment::teleport()
  95. {
  96.     Mix_PlayChannel(-1,tele,0);
  97. }
  98.  
  99. void environment::stop()
  100. {
  101.     Mix_HaltMusic();
  102. }
  103.  
  104. void environment::toggleMusic()
  105. {
  106.      // check if no music is playing
  107.     if ( Mix_PlayingMusic() == 0)
  108.      {
  109.           // play music
  110.          Mix_PlayMusic(music, -1);
  111.      }
  112.      else
  113.      {
  114.           if ( Mix_PausedMusic() == 1)
  115.           {
  116.                // resume music
  117.                Mix_ResumeMusic();
  118.           }
  119.           else
  120.           {
  121.                // music is playing, pause it
  122.                Mix_PauseMusic();
  123.           }
  124.      }
  125. }
  126.  
  127.  
  128. //Load gun change sound effects
  129. gun_change::gun_change()
  130. {
  131.     change1 = NULL;
  132.     change2 = NULL;
  133.     change3 = NULL;
  134.     change4 = NULL;
  135. }
  136. gun_change::~gun_change()
  137. {
  138.     Mix_FreeChunk(change1);
  139.      Mix_FreeChunk(change2);
  140.      Mix_FreeChunk(change3);
  141.      Mix_FreeChunk(change4);
  142. }
  143. bool gun_change::setup()
  144. {
  145.     change1 = Mix_LoadWAV("./Media/Sound/gun_change01.wav");
  146.     change2 = Mix_LoadWAV("./Media/Sound/gun_change02.wav");
  147.     change3 = Mix_LoadWAV("./Media/Sound/gun_change03.wav");
  148.     change4 = Mix_LoadWAV("./Media/Sound/gun_change04.wav");
  149.      if (change1 == NULL || change2 == NULL || change3 == NULL || change4 == NULL)
  150.           return false;
  151.      return true;
  152. }
  153.  
  154. void gun_change::gun_change1()
  155. {
  156.     Mix_PlayChannel(-1,change1,0);
  157. }
  158.  
  159. void gun_change::gun_change2()
  160. {
  161.     Mix_PlayChannel(-1,change2,0);
  162. }
  163.  
  164. void gun_change::gun_change3()
  165. {
  166.     Mix_PlayChannel(-1,change3,0);
  167. }
  168.  
  169. void gun_change::gun_change4()
  170. {
  171.     Mix_PlayChannel(-1,change4,0);
  172. }