diff --git a/src/defs.h b/src/defs.h index bf4290e..ec73322 100644 --- a/src/defs.h +++ b/src/defs.h @@ -163,15 +163,47 @@ enum enum { - SND_EXPLOSION, + SND_SELECT, + SND_BACK, SND_PISTOL, SND_MACHINE_GUN, SND_PLASMA, - SND_SPREAD, - SND_LASER, SND_THROW, + SND_SPREAD, SND_SHOTGUN, - SND_MISSILE + SND_LASER, + SND_MISSILE, + SND_RICO_1, + SND_RICO_2, + SND_GRENADE_BOUNCE, + SND_EXPLOSION, + SND_FLESH_HIT, + SND_METAL_HIT, + SND_DEATH_1, + SND_DEATH_2, + SND_DEATH_3, + SND_SPLAT, + SND_DROID_DIE_1, + SND_DROID_DIE_2, + SND_PRESSURE_PLATE, + SND_DOOR_START, + SND_DOOR_FINISH, + SND_CHERRY, + SND_ITEM, + SND_KEY, + SND_WEAPON, + SND_TELEPORT, + SND_APPEAR, + SND_MIA, + SND_WATER_IN, + SND_WATER_OUT, + SND_SLIME, + SND_DROWN, + SND_DENIED, + SND_CONFIRMED, + SND_MISSION_COMPLETE, + SND_HEART_CELL, + SND_MAX }; enum diff --git a/src/system/sound.c b/src/system/sound.c index 958773b..94f02b0 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -20,6 +20,122 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "sound.h" +static void loadSounds(void); + +static Mix_Chunk *sounds[SND_MAX]; +static Mix_Music *music; + +void initSounds(void) +{ + memset(sounds, 0, sizeof(Mix_Chunk*) * SND_MAX); + + music = NULL; + + loadSounds(); +} + +void playMusic(char *filename, int loop) +{ + if (music != NULL) + { + Mix_HaltMusic(); + Mix_FreeMusic(music); + music = NULL; + } + + music = Mix_LoadMUS(getFileLocation(filename)); + + Mix_PlayMusic(music, (loop) ? -1 : 0); +} + +void stopMusic(void) +{ + Mix_HaltMusic(); +} + +void musicSetPlaying(int playing) +{ + if (music != NULL) + { + if (playing) + { + Mix_ResumeMusic(); + } + else + { + Mix_PauseMusic(); + } + } +} + void playSound(int snd, int ch) { + Mix_PlayChannel(ch, sounds[snd], 0); +} + +static Mix_Chunk *loadSound(char *filename) +{ + return Mix_LoadWAV(getFileLocation(filename)); +} + +static void loadSounds(void) +{ + sounds[SND_SELECT] = loadSound(""); + sounds[SND_BACK] = loadSound(""); + sounds[SND_PISTOL] = loadSound(""); + sounds[SND_MACHINE_GUN] = loadSound(""); + sounds[SND_PLASMA] = loadSound(""); + sounds[SND_THROW] = loadSound(""); + sounds[SND_SPREAD] = loadSound(""); + sounds[SND_SHOTGUN] = loadSound(""); + sounds[SND_LASER] = loadSound(""); + sounds[SND_MISSILE] = loadSound(""); + sounds[SND_RICO_1] = loadSound(""); + sounds[SND_RICO_2] = loadSound(""); + sounds[SND_GRENADE_BOUNCE] = loadSound(""); + sounds[SND_EXPLOSION] = loadSound(""); + sounds[SND_FLESH_HIT] = loadSound(""); + sounds[SND_METAL_HIT] = loadSound(""); + sounds[SND_DEATH_1] = loadSound(""); + sounds[SND_DEATH_2] = loadSound(""); + sounds[SND_DEATH_3] = loadSound(""); + sounds[SND_SPLAT] = loadSound(""); + sounds[SND_DROID_DIE_1] = loadSound(""); + sounds[SND_DROID_DIE_2] = loadSound(""); + sounds[SND_PRESSURE_PLATE] = loadSound(""); + sounds[SND_DOOR_START] = loadSound(""); + sounds[SND_DOOR_FINISH] = loadSound(""); + sounds[SND_CHERRY] = loadSound(""); + sounds[SND_ITEM] = loadSound(""); + sounds[SND_KEY] = loadSound(""); + sounds[SND_WEAPON] = loadSound(""); + sounds[SND_TELEPORT] = loadSound(""); + sounds[SND_APPEAR] = loadSound(""); + sounds[SND_MIA] = loadSound(""); + sounds[SND_WATER_IN] = loadSound(""); + sounds[SND_WATER_OUT] = loadSound(""); + sounds[SND_SLIME] = loadSound(""); + sounds[SND_DROWN] = loadSound(""); + sounds[SND_DENIED] = loadSound(""); + sounds[SND_CONFIRMED] = loadSound(""); + sounds[SND_MISSION_COMPLETE] = loadSound(""); + sounds[SND_HEART_CELL] = loadSound(""); +} + +void destroySounds(void) +{ + int i; + + for (i = 0 ; i < SND_MAX ; i++) + { + if (sounds[i]) + { + Mix_FreeChunk(sounds[i]); + } + } + + if (music != NULL) + { + Mix_FreeMusic(music); + } } diff --git a/src/system/sound.h b/src/system/sound.h index 8ad0dc9..ae05f71 100644 --- a/src/system/sound.h +++ b/src/system/sound.h @@ -19,3 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../common.h" +#include "SDL2/SDL_mixer.h" + +extern char *getFileLocation(char *filename);