diff --git a/src/Starfighter.cpp b/src/Starfighter.cpp index eb0b903..de0c35d 100644 --- a/src/Starfighter.cpp +++ b/src/Starfighter.cpp @@ -107,7 +107,7 @@ int main(int argc, char **argv) } freeGraphics(); - loadSound(); + audio_loadSounds(); initWeapons(); diff --git a/src/aliens.cpp b/src/aliens.cpp index 3042db3..bbb3e7b 100644 --- a/src/aliens.cpp +++ b/src/aliens.cpp @@ -694,7 +694,7 @@ void alien_move(object *alien) alien->hit = 3; alien->dx *= -1; alien->dy *= -1; - playSound(SFX_HIT, alien->x); + audio_playSound(SFX_HIT, alien->x); } } @@ -712,10 +712,10 @@ void alien_move(object *alien) if (!engine.cheatShield) player.shield -= alien->shield; alien->shield = 0; - playSound(SFX_EXPLOSION, alien->x); + audio_playSound(SFX_EXPLOSION, alien->x); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); player.hit = 5; - playSound(SFX_HIT, player.x); + audio_playSound(SFX_HIT, player.x); } if (alien->classDef == CD_ASTEROID2) @@ -723,10 +723,10 @@ void alien_move(object *alien) if (!engine.cheatShield) player.shield -= alien->shield; alien->shield = 0; - playSound(SFX_EXPLOSION, alien->x); + audio_playSound(SFX_EXPLOSION, alien->x); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); player.hit = 5; - playSound(SFX_HIT, player.x); + audio_playSound(SFX_HIT, player.x); } if (alien->classDef == CD_BARRIER) @@ -734,7 +734,7 @@ void alien_move(object *alien) if (!engine.cheatShield) player.shield--; player.hit = 5; - playSound(SFX_HIT, player.x); + audio_playSound(SFX_HIT, player.x); } } } diff --git a/src/audio.cpp b/src/audio.cpp index e6d778c..1add0f2 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -19,9 +19,30 @@ along with this program. If not, see . #include "Starfighter.h" -Mix_Chunk *sound[MAX_SOUNDS]; +static Mix_Chunk *sound[SFX_MAX]; +static Mix_Music *music = NULL; -void playSound(int sid, float x) +void audio_loadSounds() +{ + sound[SFX_EXPLOSION] = Mix_LoadWAV("sound/explode.ogg"); + sound[SFX_HIT] = Mix_LoadWAV("sound/explode2.ogg"); + sound[SFX_DEATH] = Mix_LoadWAV("sound/maledeath.ogg"); + sound[SFX_MISSILE] = Mix_LoadWAV("sound/missile.ogg"); + sound[SFX_PLASMA] = Mix_LoadWAV("sound/plasma.ogg"); + sound[SFX_CLOCK] = Mix_LoadWAV("sound/clock.ogg"); + sound[SFX_FLY] = Mix_LoadWAV("sound/flyby.ogg"); + sound[SFX_ENERGYRAY] = Mix_LoadWAV("sound/beamLaser.ogg"); + sound[SFX_PICKUP] = Mix_LoadWAV("sound/item.ogg"); + sound[SFX_SHIELDUP] = Mix_LoadWAV("sound/shield.ogg"); + sound[SFX_CLOAK] = Mix_LoadWAV("sound/cloak.ogg"); + sound[SFX_DEBRIS] = Mix_LoadWAV("sound/explode3.ogg"); + sound[SFX_DEBRIS2] = Mix_LoadWAV("sound/explode4.ogg"); + sound[SFX_LASER] = Mix_LoadWAV("sound/laser.ogg"); + sound[SFX_PLASMA2] = Mix_LoadWAV("sound/plasma2.ogg"); + sound[SFX_PLASMA3] = Mix_LoadWAV("sound/plasma3.ogg"); +} + +void audio_playSound(int sid, float x) { if ((!engine.useSound) || (!engine.useAudio)) return; @@ -65,40 +86,49 @@ void playSound(int sid, float x) freechannel = 4; } - int angle = atanf((x - 400) / 400) * 180 / M_PI; - int attenuation = fabsf(x - 400) / 40; + int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI; + int attenuation = fabsf(x - (screen->w / 2)) / 40; - if(angle < 0) + if (angle < 0) angle += 360; - if(attenuation > 255) + if (attenuation > 255) attenuation = 255; Mix_SetPosition(channel, angle, attenuation); Mix_PlayChannel(channel, sound[sid], 0); } -Mix_Chunk *loadSound(const char *filename) -{ - Mix_Chunk *chunk; - - chunk = Mix_LoadWAV(filename); - - return chunk; -} - -void loadMusic(const char *filename) +void audio_haltMusic() { if (Mix_PlayingMusic()) Mix_HaltMusic(); - if (engine.music != NULL) - Mix_FreeMusic(engine.music); - - engine.music = Mix_LoadMUS(filename); + if (music != NULL) + { + Mix_FreeMusic(music); + music = NULL; + } } -void playRandomTrack() +void audio_setMusicVolume(int volume) +{ + if (engine.useMusic && engine.useAudio) + Mix_VolumeMusic(volume); +} + +void audio_playMusic(const char *filename, int loops) +{ + if (engine.useMusic && engine.useAudio) + { + audio_haltMusic(); + music = Mix_LoadMUS(filename); + audio_setMusicVolume(100); + Mix_PlayMusic(music, loops); + } +} + +void audio_playRandomTrack() { if ((!engine.useMusic) || (!engine.useAudio)) return; @@ -112,20 +142,36 @@ void playRandomTrack() switch(currentGame.area) { case 0: - loadMusic("music/railjet_short.ogg"); + audio_playMusic("music/railjet_short.ogg", -1); break; case 5: case 11: case 18: case 25: - loadMusic("music/orbital_colossus.ogg"); + audio_playMusic("music/orbital_colossus.ogg", -1); break; case 26: - loadMusic("music/RE.ogg"); + audio_playMusic("music/RE.ogg", -1); break; default: - loadMusic(track[rand() % tracks]); + audio_playMusic(track[rand() % tracks], -1); + } +} + +void audio_free() +{ + for (int i = 0 ; i < SFX_MAX ; i++) + { + if (sound[i] != NULL) + { + Mix_FreeChunk(sound[i]); + sound[i] = NULL; + } } - Mix_PlayMusic(engine.music, -1); + if (music != NULL) + { + Mix_FreeMusic(music); + music = NULL; + } } diff --git a/src/audio.h b/src/audio.h index 960a7a1..fb7768c 100644 --- a/src/audio.h +++ b/src/audio.h @@ -20,11 +20,12 @@ along with this program. If not, see . #ifndef AUDIO_H #define AUDIO_H -extern Mix_Chunk *sound[MAX_SOUNDS]; - -extern void playSound(int sid, float x = 400); -extern Mix_Chunk *loadSound(const char *filename); -extern void loadMusic(const char *filename); -extern void playRandomTrack(); +void audio_loadSounds(); +void audio_playSound(int sid, float x); +void audio_haltMusic(); +void audio_setMusicVolume(int volume); +void audio_playMusic(const char *filename, int loops); +void audio_playRandomTrack(); +void audio_free(); #endif diff --git a/src/bullets.cpp b/src/bullets.cpp index f10e44d..3db5a9a 100644 --- a/src/bullets.cpp +++ b/src/bullets.cpp @@ -156,16 +156,16 @@ void fireBullet(object *attacker, int weaponType) case WT_PLASMA: case WT_SPREAD: case WT_DIRECTIONAL: - playSound(SFX_PLASMA, attacker->x); + audio_playSound(SFX_PLASMA, attacker->x); break; case WT_ROCKET: - playSound(SFX_MISSILE, attacker->x); + audio_playSound(SFX_MISSILE, attacker->x); break; case WT_LASER: - playSound(SFX_LASER, attacker->x); + audio_playSound(SFX_LASER, attacker->x); break; case WT_CHARGER: - playSound(SFX_PLASMA3, attacker->x); + audio_playSound(SFX_PLASMA3, attacker->x); break; } @@ -275,7 +275,7 @@ Fill in later... */ static void alien_destroy(object *alien, object *attacker) { - playSound(SFX_EXPLOSION, alien->x); + audio_playSound(SFX_EXPLOSION, alien->x); // Chain reaction destruction if needed if (alien->flags & FL_DAMAGEOWNER) @@ -436,11 +436,11 @@ void fireRay(object *attacker) player.shield--; addExplosion(player.x, player.y, E_SMALL_EXPLOSION); - playSound(SFX_HIT, player.x); + audio_playSound(SFX_HIT, player.x); if (player.shield < 1) { - playSound(SFX_DEATH, player.x); - playSound(SFX_EXPLOSION, player.x); + audio_playSound(SFX_DEATH, player.x); + audio_playSound(SFX_EXPLOSION, player.x); } } } @@ -459,7 +459,7 @@ void fireRay(object *attacker) { anEnemy->shield--; addExplosion(anEnemy->x, anEnemy->y, E_SMALL_EXPLOSION); - playSound(SFX_HIT, anEnemy->x); + audio_playSound(SFX_HIT, anEnemy->x); if (anEnemy->shield < 1) { alien_destroy(anEnemy, attacker->owner); @@ -647,7 +647,7 @@ void doBullets() bullet->active = false; } - playSound(SFX_HIT, alien->x); + audio_playSound(SFX_HIT, alien->x); if (alien->AIType == AI_EVASIVE) alien->thinktime = 0; @@ -709,7 +709,7 @@ void doBullets() bullet->active = false; } - playSound(SFX_HIT, player.x); + audio_playSound(SFX_HIT, player.x); if (bullet->id == WT_ROCKET) addExplosion(bullet->x, bullet->y, E_BIG_EXPLOSION); @@ -731,11 +731,11 @@ void doBullets() { bullet->active = false; addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION); - playSound(SFX_HIT, theCargo->x); + audio_playSound(SFX_HIT, theCargo->x); if (theCargo->collectType != P_PHOEBE) { theCargo->active = false; - playSound(SFX_EXPLOSION, theCargo->x); + audio_playSound(SFX_EXPLOSION, theCargo->x); for (int i = 0 ; i < 10 ; i++) addExplosion(theCargo->x + rrand(-15, 15), theCargo->y + rrand(-15, 15), E_BIG_EXPLOSION); updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1); @@ -754,7 +754,7 @@ void doBullets() { if ((bullet->flags & WF_TIMEDEXPLOSION) || (bullet->id == WT_CHARGER)) { - playSound(SFX_EXPLOSION, bullet->x); + audio_playSound(SFX_EXPLOSION, bullet->x); for (int i = 0 ; i < 10 ; i++) addExplosion(bullet->x + rrand(-35, 35), bullet->y + rrand(-35, 35), E_BIG_EXPLOSION); diff --git a/src/collectable.cpp b/src/collectable.cpp index 41f1bc2..b9867dd 100644 --- a/src/collectable.cpp +++ b/src/collectable.cpp @@ -226,7 +226,7 @@ static void explodeMine(collectables *collectable) { if ((collectable->x >= 0) && (collectable->x <= screen->w) && (collectable->y >= 0) && (collectable->y <= screen->h)) - playSound(SFX_EXPLOSION, collectable->x); + audio_playSound(SFX_EXPLOSION, collectable->x); for (int i = 0 ; i < 10 ; i++) addExplosion(collectable->x + rand() % 25 - rand() % 25, @@ -448,9 +448,9 @@ void doCollectables() { setInfoLine(temp, FONT_WHITE); if (collectable->type == P_SHIELD) - playSound(SFX_SHIELDUP, player.x); + audio_playSound(SFX_SHIELDUP, player.x); else - playSound(SFX_PICKUP, player.x); + audio_playSound(SFX_PICKUP, player.x); } } diff --git a/src/debris.cpp b/src/debris.cpp index 488e788..db132ff 100644 --- a/src/debris.cpp +++ b/src/debris.cpp @@ -22,9 +22,9 @@ along with this program. If not, see . void addDebris(int x, int y, int amount) { if ((rand() % 2) == 0) - playSound(SFX_DEBRIS, x); + audio_playSound(SFX_DEBRIS, x); else - playSound(SFX_DEBRIS2, x); + audio_playSound(SFX_DEBRIS2, x); object *debris; diff --git a/src/defs.h b/src/defs.h index c4b0fc8..2774257 100644 --- a/src/defs.h +++ b/src/defs.h @@ -86,7 +86,6 @@ along with this program. If not, see . #define MAX_WEAPONS 20 #define MAX_SHAPES 100 #define MAX_SHIPSHAPES 120 -#define MAX_SOUNDS 17 #define MAX_ALIENS 25 #define MAX_TEXTSHAPES 150 #define MAX_FONTSHAPES 6 @@ -339,7 +338,8 @@ enum { SFX_DEBRIS2, SFX_LASER, SFX_PLASMA2, - SFX_PLASMA3 + SFX_PLASMA3, + SFX_MAX }; enum { diff --git a/src/game.cpp b/src/game.cpp index 7e6fd5e..39b7802 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -541,7 +541,7 @@ int mainGameLoop() else if ((currentGame.area == 26) && (engine.musicVolume > 0)) { limitFloat(&(engine.musicVolume -= 0.2), 0, 100); - Mix_VolumeMusic((int)engine.musicVolume); + audio_setMusicVolume((int)engine.musicVolume); } else { @@ -556,7 +556,7 @@ int mainGameLoop() else { limitFloat(&(engine.musicVolume -= 0.2), 0, 100); - Mix_VolumeMusic((int)engine.musicVolume); + audio_setMusicVolume((int)engine.musicVolume); if (SDL_GetTicks() >= engine.missionCompleteTimer) { engine.done = 1; @@ -721,7 +721,7 @@ int mainGameLoop() alien->flags -= FL_ISCLOAKED; else alien->flags += FL_ISCLOAKED; - playSound(SFX_CLOAK, alien->x); + audio_playSound(SFX_CLOAK, alien->x); } if (alien->classDef == CD_BARRIER) @@ -780,7 +780,7 @@ int mainGameLoop() (alien->ammo[0] == 250)) { alien->flags += FL_FIRERAY; - playSound(SFX_ENERGYRAY, alien->x); + audio_playSound(SFX_ENERGYRAY, alien->x); } } } @@ -932,14 +932,14 @@ int mainGameLoop() // specific to Boss 1 if ((currentGame.area == 5) && (aliens[WC_BOSS].flags & FL_ESCAPED)) { - playSound(SFX_DEATH, aliens[WC_BOSS].x); + audio_playSound(SFX_DEATH, aliens[WC_BOSS].x); clearScreen(white); updateScreen(); for (int i = 0 ; i < 300 ; i++) { SDL_Delay(10); if ((rand() % 25) == 0) - playSound(SFX_EXPLOSION, aliens[WC_BOSS].x); + audio_playSound(SFX_EXPLOSION, aliens[WC_BOSS].x); } SDL_Delay(1000); break; diff --git a/src/init.cpp b/src/init.cpp index e9497ea..f40bea4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -224,7 +224,7 @@ void initSystem() { if (Mix_OpenAudio(44100, AUDIO_S16, engine.useAudio * 2, 1024) < 0) { - printf("Warning: Couldn't set 44100 Hz 16-bit stereo audio - Reason: %s\n", Mix_GetError()); + printf("Warning: Couldn't set 44100 Hz 16-bit stereo audio - Reason:\n%s\n", Mix_GetError()); printf("Sound and Music will be disabled\n"); engine.useAudio = false; } @@ -246,7 +246,7 @@ void cleanUp() { freeGraphics(); SDL_FreeSurface(background); - freeSound(); + audio_free(); resetLists(); delete(engine.bulletHead); delete(engine.explosionHead); diff --git a/src/intermission.cpp b/src/intermission.cpp index ac36e43..469f730 100644 --- a/src/intermission.cpp +++ b/src/intermission.cpp @@ -409,20 +409,13 @@ static void showOptions(SDL_Surface *optionsSurface) if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 222, 45, 22)) { engine.useMusic = true; - if (engine.useAudio) - { - if (Mix_PausedMusic() == 1) - Mix_ResumeMusic(); - else - Mix_PlayMusic(engine.music, -1); - } + audio_playMusic("music/through_space.ogg", -1); } if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22)) { engine.useMusic = false; - if (engine.useAudio) - Mix_PauseMusic(); + audio_haltMusic(); } if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22)) @@ -469,8 +462,6 @@ int galaxyMap() initSaveSlots(); - loadMusic("music/through_space.ogg"); - loadBackground(systemBackground[currentGame.system]); char string[25]; @@ -556,7 +547,7 @@ int galaxyMap() int rtn = 0; if ((engine.useAudio) && (engine.useMusic)) - Mix_PlayMusic(engine.music, -1); + audio_playMusic("music/through_space.ogg", -1); textObject iconInfo[12]; @@ -833,7 +824,7 @@ int galaxyMap() delayFrame(); } - Mix_HaltMusic(); + audio_haltMusic(); SDL_FreeSurface(statsSurface); SDL_FreeSurface(savesSurface); SDL_FreeSurface(optionsSurface); diff --git a/src/misc.cpp b/src/misc.cpp index 795eb8a..b1ff406 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -235,7 +235,7 @@ void doInfo() { if ((engine.seconds > 1) && (engine.seconds <= 11) && (engine.minutes == 0)) { - playSound(SFX_CLOCK); + audio_playSound(SFX_CLOCK, screen->w / 2); } if (engine.seconds > 0) diff --git a/src/missions.cpp b/src/missions.cpp index 668e0fa..69d592f 100644 --- a/src/missions.cpp +++ b/src/missions.cpp @@ -516,9 +516,7 @@ static char revealHiddenObjectives() aliens[WC_KLINE].y = player.y; aliens[WC_KLINE].flags |= FL_IMMORTAL | FL_NOFIRE; player_setTarget(WC_KLINE); - loadMusic("music/last_cyber_dance.ogg"); - if ((engine.useAudio) && (engine.useMusic)) - Mix_PlayMusic(engine.music, -1); + audio_playMusic("music/last_cyber_dance.ogg", -1); } } @@ -789,7 +787,7 @@ void missionBriefScreen() textSurface(11, "Power", 25, 570, FONT_WHITE); textSurface(12, "Output", 250, 570, FONT_WHITE); textSurface(13, "Cooler", 485, 570, FONT_WHITE); - playRandomTrack(); + audio_playRandomTrack(); if (currentGame.area != MAX_MISSIONS - 1) { @@ -915,7 +913,7 @@ void missionFinishedScreen() if (player.weaponType[1] == W_LASER) player.ammo[1] = 1; - Mix_HaltMusic(); + audio_haltMusic(); } /* diff --git a/src/player.cpp b/src/player.cpp index 03068d0..73d6358 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -209,7 +209,7 @@ void doPlayer() if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) && (currentMission.remainingObjectives1 == 0)) { - playSound(SFX_FLY); + audio_playSound(SFX_FLY, screen->w / 2); engine.done = 2; engine.missionCompleteTimer = (SDL_GetTicks() - 1); } @@ -322,8 +322,8 @@ void doPlayer() aliens[i].flags |= FL_LEAVESECTOR; } - playSound(SFX_DEATH, player.x); - playSound(SFX_EXPLOSION, player.x); + audio_playSound(SFX_DEATH, player.x); + audio_playSound(SFX_EXPLOSION, player.x); } engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0; @@ -565,7 +565,7 @@ void leaveSector() if (player.x <= -100) { engine.done = 2; - playSound(SFX_FLY); + audio_playSound(SFX_FLY, screen->w / 2); } } diff --git a/src/resources.cpp b/src/resources.cpp index ac36e19..5f2a7b3 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -144,38 +144,6 @@ void loadGameGraphics() setWeaponShapes(); } -void loadSound() -{ - sound[SFX_EXPLOSION] = loadSound("sound/explode.ogg"); - sound[SFX_HIT] = loadSound("sound/explode2.ogg"); - sound[SFX_DEATH] = loadSound("sound/maledeath.ogg"); - sound[SFX_MISSILE] = loadSound("sound/missile.ogg"); - sound[SFX_PLASMA] = loadSound("sound/plasma.ogg"); - sound[SFX_CLOCK] = loadSound("sound/clock.ogg"); - sound[SFX_FLY] = loadSound("sound/flyby.ogg"); - sound[SFX_ENERGYRAY] = loadSound("sound/beamLaser.ogg"); - sound[SFX_PICKUP] = loadSound("sound/item.ogg"); - sound[SFX_SHIELDUP] = loadSound("sound/shield.ogg"); - sound[SFX_CLOAK] = loadSound("sound/cloak.ogg"); - sound[SFX_DEBRIS] = loadSound("sound/explode3.ogg"); - sound[SFX_DEBRIS2] = loadSound("sound/explode4.ogg"); - sound[SFX_LASER] = loadSound("sound/laser.ogg"); - sound[SFX_PLASMA2] = loadSound("sound/plasma2.ogg"); - sound[SFX_PLASMA3] = loadSound("sound/plasma3.ogg"); -} - -void freeSound() -{ - for (int i = 0 ; i < MAX_SOUNDS ; i++) - { - if (sound[i] != NULL) - Mix_FreeChunk(sound[i]); - } - - if (engine.music != NULL) - Mix_FreeMusic(engine.music); -} - /* Custom loading to alter the font color before doing diff --git a/src/resources.h b/src/resources.h index 1ce92e2..f0e75c5 100644 --- a/src/resources.h +++ b/src/resources.h @@ -22,8 +22,6 @@ along with this program. If not, see . extern void loadBackground(const char *filename); extern void loadGameGraphics(); -extern void loadSound(); -extern void freeSound(); extern void loadFont(); #endif diff --git a/src/structs.h b/src/structs.h index 34374cc..bf5604c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -244,8 +244,6 @@ struct globalEngineVariables { float smx; float smy; - Mix_Music *music; - object *bulletHead; object *bulletTail; object *explosionHead; diff --git a/src/title.cpp b/src/title.cpp index 9ac9429..408a1fe 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -188,8 +188,6 @@ int doTitle() signed char continueSaveSlot = initSaveSlots(); - loadMusic("music/walking_among_androids.ogg"); - loadBackground("gfx/spirit.jpg"); SDL_Surface *prlogo, *sflogo; @@ -266,8 +264,7 @@ int doTitle() flushInput(); engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; - if ((engine.useMusic) && (engine.useAudio)) - Mix_PlayMusic(engine.music, 1); + audio_playMusic("music/walking_among_androids.ogg", 1); while (!engine.done) { @@ -467,14 +464,12 @@ int doTitle() if (engine.useMusic) { - if (Mix_PausedMusic() == 1) - Mix_ResumeMusic(); - else - Mix_PlayMusic(engine.music, 1); + audio_playMusic( + "music/walking_among_androids.ogg", 1); } else { - Mix_PauseMusic(); + audio_haltMusic(); } } else if (selectedOption == 3) @@ -521,7 +516,7 @@ int doTitle() delayFrame(); } - Mix_HaltMusic(); + audio_haltMusic(); SDL_FreeSurface(prlogo); SDL_FreeSurface(sflogo); @@ -626,8 +621,6 @@ void gameover() engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; engine.gameSection = SECTION_INTERMISSION; - loadMusic("music/death.ogg"); - SDL_Surface *gameover = loadImage("gfx/gameover.png"); clearScreen(black); @@ -635,11 +628,7 @@ void gameover() clearScreen(black); SDL_Delay(1000); - if ((engine.useMusic) && (engine.useAudio)) - { - Mix_VolumeMusic(100); - Mix_PlayMusic(engine.music, 1); - } + audio_playMusic("music/death.ogg", 1); int x = (screen->w - gameover->w) / 2; int y = (screen->h - gameover->h) / 2; @@ -667,10 +656,7 @@ void gameover() } SDL_FreeSurface(gameover); - - if ((engine.useMusic) && (engine.useAudio)) - Mix_HaltMusic(); - + audio_haltMusic(); flushBuffer(); } @@ -680,9 +666,6 @@ void doCredits() flushBuffer(); freeGraphics(); - if ((engine.useMusic) && (engine.useAudio)) - loadMusic("music/rise_of_spirit.ogg"); - FILE *fp; int lastCredit = -1; @@ -699,11 +682,7 @@ void doCredits() drawBackGround(); - if ((engine.useMusic) && (engine.useAudio)) - { - Mix_VolumeMusic(100); - Mix_PlayMusic(engine.music, 1); - } + audio_playMusic("music/rise_of_spirit.ogg", 1); fp = fopen("data/credits.txt", "rb"); // FIXME: It would be nice for the size of this array to be determined