#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
#include "CPSound.h"
//Load functions for weapon sound effects
weapon_fire::weapon_fire()
{
fireB = NULL;
fireC = NULL;
fireL = NULL;
fireM = NULL;
fireP = NULL;
}
weapon_fire::~weapon_fire()
{
Mix_FreeChunk(fireB);
Mix_FreeChunk(fireC);
Mix_FreeChunk(fireL);
Mix_FreeChunk(fireM);
Mix_FreeChunk(fireP);
}
bool weapon_fire::setup()
{
fireB = Mix_LoadWAV("./Media/Sound/blaster.wav");
fireC = Mix_LoadWAV("./Media/Sound/cannon.wav");
fireL = Mix_LoadWAV("./Media/Sound/laser.wav");
fireM = Mix_LoadWAV("./Media/Sound/missile.wav");
fireP = Mix_LoadWAV("./Media/Sound/plasma.wav");
if (fireB == NULL || fireC == NULL || fireL == NULL | fireM == NULL | fireP == NULL)
return false;
return true;
}
void weapon_fire::blaster()
{
Mix_PlayChannel(-1, fireB, 0);
}
void weapon_fire::cannon()
{
Mix_PlayChannel(-1, fireC, 0);
}
void weapon_fire::laser()
{
Mix_PlayChannel(-1, fireL, 0);
}
void weapon_fire::missile()
{
Mix_PlayChannel(-1, fireM, 0);
}
void weapon_fire::plasma()
{
Mix_PlayChannel(-1, fireP, 0);
}
//Load background or environment effects
environment::environment()
{
music = NULL;
boom = NULL;
tele = NULL;
}
environment::~environment()
{
Mix_FreeMusic(music);
Mix_FreeChunk(boom);
Mix_FreeChunk(tele);
}
bool environment::setup()
{
music = Mix_LoadMUS("./Media/Sound/Music/Plunder_the_Galaxy.wav"); // trance_industrial_raw_mix.wav");
boom = Mix_LoadWAV("./Media/Sound/explosion.wav");
tele = Mix_LoadWAV("./Media/Sound/teleport_activate.wav");
if (music == NULL || boom == NULL || tele == NULL)
return false;
return true;
}
void environment::background_music()
{
Mix_PlayMusic(music, -1);
}
void environment::explosion()
{
Mix_PlayChannel(-1, boom, 0);
}
void environment::teleport()
{
Mix_PlayChannel(-1,tele,0);
}
void environment::stop()
{
Mix_HaltMusic();
}
void environment::toggleMusic()
{
// check if no music is playing
if ( Mix_PlayingMusic() == 0)
{
// play music
Mix_PlayMusic(music, -1);
}
else
{
if ( Mix_PausedMusic() == 1)
{
// resume music
Mix_ResumeMusic();
}
else
{
// music is playing, pause it
Mix_PauseMusic();
}
}
}
//Load gun change sound effects
gun_change::gun_change()
{
change1 = NULL;
change2 = NULL;
change3 = NULL;
change4 = NULL;
}
gun_change::~gun_change()
{
Mix_FreeChunk(change1);
Mix_FreeChunk(change2);
Mix_FreeChunk(change3);
Mix_FreeChunk(change4);
}
bool gun_change::setup()
{
change1 = Mix_LoadWAV("./Media/Sound/gun_change01.wav");
change2 = Mix_LoadWAV("./Media/Sound/gun_change02.wav");
change3 = Mix_LoadWAV("./Media/Sound/gun_change03.wav");
change4 = Mix_LoadWAV("./Media/Sound/gun_change04.wav");
if (change1 == NULL || change2 == NULL || change3 == NULL || change4 == NULL)
return false;
return true;
}
void gun_change::gun_change1()
{
Mix_PlayChannel(-1,change1,0);
}
void gun_change::gun_change2()
{
Mix_PlayChannel(-1,change2,0);
}
void gun_change::gun_change3()
{
Mix_PlayChannel(-1,change3,0);
}
void gun_change::gun_change4()
{
Mix_PlayChannel(-1,change4,0);
}