Updated audio module.

This commit is contained in:
onpon4 2015-03-08 10:38:58 -04:00
parent f54579a41f
commit 28cc1fcc6d
18 changed files with 135 additions and 156 deletions

View File

@ -107,7 +107,7 @@ int main(int argc, char **argv)
} }
freeGraphics(); freeGraphics();
loadSound(); audio_loadSounds();
initWeapons(); initWeapons();

View File

@ -694,7 +694,7 @@ void alien_move(object *alien)
alien->hit = 3; alien->hit = 3;
alien->dx *= -1; alien->dx *= -1;
alien->dy *= -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) if (!engine.cheatShield)
player.shield -= alien->shield; player.shield -= alien->shield;
alien->shield = 0; alien->shield = 0;
playSound(SFX_EXPLOSION, alien->x); audio_playSound(SFX_EXPLOSION, alien->x);
setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED);
player.hit = 5; player.hit = 5;
playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
} }
if (alien->classDef == CD_ASTEROID2) if (alien->classDef == CD_ASTEROID2)
@ -723,10 +723,10 @@ void alien_move(object *alien)
if (!engine.cheatShield) if (!engine.cheatShield)
player.shield -= alien->shield; player.shield -= alien->shield;
alien->shield = 0; alien->shield = 0;
playSound(SFX_EXPLOSION, alien->x); audio_playSound(SFX_EXPLOSION, alien->x);
setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED);
player.hit = 5; player.hit = 5;
playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
} }
if (alien->classDef == CD_BARRIER) if (alien->classDef == CD_BARRIER)
@ -734,7 +734,7 @@ void alien_move(object *alien)
if (!engine.cheatShield) if (!engine.cheatShield)
player.shield--; player.shield--;
player.hit = 5; player.hit = 5;
playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
} }
} }
} }

View File

@ -19,9 +19,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Starfighter.h" #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)) if ((!engine.useSound) || (!engine.useAudio))
return; return;
@ -65,8 +86,8 @@ void playSound(int sid, float x)
freechannel = 4; freechannel = 4;
} }
int angle = atanf((x - 400) / 400) * 180 / M_PI; int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI;
int attenuation = fabsf(x - 400) / 40; int attenuation = fabsf(x - (screen->w / 2)) / 40;
if (angle < 0) if (angle < 0)
angle += 360; angle += 360;
@ -78,27 +99,36 @@ void playSound(int sid, float x)
Mix_PlayChannel(channel, sound[sid], 0); Mix_PlayChannel(channel, sound[sid], 0);
} }
Mix_Chunk *loadSound(const char *filename) void audio_haltMusic()
{
Mix_Chunk *chunk;
chunk = Mix_LoadWAV(filename);
return chunk;
}
void loadMusic(const char *filename)
{ {
if (Mix_PlayingMusic()) if (Mix_PlayingMusic())
Mix_HaltMusic(); Mix_HaltMusic();
if (engine.music != NULL) if (music != NULL)
Mix_FreeMusic(engine.music); {
Mix_FreeMusic(music);
engine.music = Mix_LoadMUS(filename); 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)) if ((!engine.useMusic) || (!engine.useAudio))
return; return;
@ -112,20 +142,36 @@ void playRandomTrack()
switch(currentGame.area) switch(currentGame.area)
{ {
case 0: case 0:
loadMusic("music/railjet_short.ogg"); audio_playMusic("music/railjet_short.ogg", -1);
break; break;
case 5: case 5:
case 11: case 11:
case 18: case 18:
case 25: case 25:
loadMusic("music/orbital_colossus.ogg"); audio_playMusic("music/orbital_colossus.ogg", -1);
break; break;
case 26: case 26:
loadMusic("music/RE.ogg"); audio_playMusic("music/RE.ogg", -1);
break; break;
default: default:
loadMusic(track[rand() % tracks]); audio_playMusic(track[rand() % tracks], -1);
}
} }
Mix_PlayMusic(engine.music, -1); void audio_free()
{
for (int i = 0 ; i < SFX_MAX ; i++)
{
if (sound[i] != NULL)
{
Mix_FreeChunk(sound[i]);
sound[i] = NULL;
}
}
if (music != NULL)
{
Mix_FreeMusic(music);
music = NULL;
}
} }

View File

@ -20,11 +20,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef AUDIO_H #ifndef AUDIO_H
#define AUDIO_H #define AUDIO_H
extern Mix_Chunk *sound[MAX_SOUNDS]; void audio_loadSounds();
void audio_playSound(int sid, float x);
extern void playSound(int sid, float x = 400); void audio_haltMusic();
extern Mix_Chunk *loadSound(const char *filename); void audio_setMusicVolume(int volume);
extern void loadMusic(const char *filename); void audio_playMusic(const char *filename, int loops);
extern void playRandomTrack(); void audio_playRandomTrack();
void audio_free();
#endif #endif

View File

@ -156,16 +156,16 @@ void fireBullet(object *attacker, int weaponType)
case WT_PLASMA: case WT_PLASMA:
case WT_SPREAD: case WT_SPREAD:
case WT_DIRECTIONAL: case WT_DIRECTIONAL:
playSound(SFX_PLASMA, attacker->x); audio_playSound(SFX_PLASMA, attacker->x);
break; break;
case WT_ROCKET: case WT_ROCKET:
playSound(SFX_MISSILE, attacker->x); audio_playSound(SFX_MISSILE, attacker->x);
break; break;
case WT_LASER: case WT_LASER:
playSound(SFX_LASER, attacker->x); audio_playSound(SFX_LASER, attacker->x);
break; break;
case WT_CHARGER: case WT_CHARGER:
playSound(SFX_PLASMA3, attacker->x); audio_playSound(SFX_PLASMA3, attacker->x);
break; break;
} }
@ -275,7 +275,7 @@ Fill in later...
*/ */
static void alien_destroy(object *alien, object *attacker) static void alien_destroy(object *alien, object *attacker)
{ {
playSound(SFX_EXPLOSION, alien->x); audio_playSound(SFX_EXPLOSION, alien->x);
// Chain reaction destruction if needed // Chain reaction destruction if needed
if (alien->flags & FL_DAMAGEOWNER) if (alien->flags & FL_DAMAGEOWNER)
@ -436,11 +436,11 @@ void fireRay(object *attacker)
player.shield--; player.shield--;
addExplosion(player.x, player.y, E_SMALL_EXPLOSION); addExplosion(player.x, player.y, E_SMALL_EXPLOSION);
playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
if (player.shield < 1) if (player.shield < 1)
{ {
playSound(SFX_DEATH, player.x); audio_playSound(SFX_DEATH, player.x);
playSound(SFX_EXPLOSION, player.x); audio_playSound(SFX_EXPLOSION, player.x);
} }
} }
} }
@ -459,7 +459,7 @@ void fireRay(object *attacker)
{ {
anEnemy->shield--; anEnemy->shield--;
addExplosion(anEnemy->x, anEnemy->y, E_SMALL_EXPLOSION); addExplosion(anEnemy->x, anEnemy->y, E_SMALL_EXPLOSION);
playSound(SFX_HIT, anEnemy->x); audio_playSound(SFX_HIT, anEnemy->x);
if (anEnemy->shield < 1) if (anEnemy->shield < 1)
{ {
alien_destroy(anEnemy, attacker->owner); alien_destroy(anEnemy, attacker->owner);
@ -647,7 +647,7 @@ void doBullets()
bullet->active = false; bullet->active = false;
} }
playSound(SFX_HIT, alien->x); audio_playSound(SFX_HIT, alien->x);
if (alien->AIType == AI_EVASIVE) if (alien->AIType == AI_EVASIVE)
alien->thinktime = 0; alien->thinktime = 0;
@ -709,7 +709,7 @@ void doBullets()
bullet->active = false; bullet->active = false;
} }
playSound(SFX_HIT, player.x); audio_playSound(SFX_HIT, player.x);
if (bullet->id == WT_ROCKET) if (bullet->id == WT_ROCKET)
addExplosion(bullet->x, bullet->y, E_BIG_EXPLOSION); addExplosion(bullet->x, bullet->y, E_BIG_EXPLOSION);
@ -731,11 +731,11 @@ void doBullets()
{ {
bullet->active = false; bullet->active = false;
addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION); addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION);
playSound(SFX_HIT, theCargo->x); audio_playSound(SFX_HIT, theCargo->x);
if (theCargo->collectType != P_PHOEBE) if (theCargo->collectType != P_PHOEBE)
{ {
theCargo->active = false; theCargo->active = false;
playSound(SFX_EXPLOSION, theCargo->x); audio_playSound(SFX_EXPLOSION, theCargo->x);
for (int i = 0 ; i < 10 ; i++) for (int i = 0 ; i < 10 ; i++)
addExplosion(theCargo->x + rrand(-15, 15), theCargo->y + rrand(-15, 15), E_BIG_EXPLOSION); addExplosion(theCargo->x + rrand(-15, 15), theCargo->y + rrand(-15, 15), E_BIG_EXPLOSION);
updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1); updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1);
@ -754,7 +754,7 @@ void doBullets()
{ {
if ((bullet->flags & WF_TIMEDEXPLOSION) || (bullet->id == WT_CHARGER)) 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++) for (int i = 0 ; i < 10 ; i++)
addExplosion(bullet->x + rrand(-35, 35), bullet->y + rrand(-35, 35), E_BIG_EXPLOSION); addExplosion(bullet->x + rrand(-35, 35), bullet->y + rrand(-35, 35), E_BIG_EXPLOSION);

View File

@ -226,7 +226,7 @@ static void explodeMine(collectables *collectable)
{ {
if ((collectable->x >= 0) && (collectable->x <= screen->w) && if ((collectable->x >= 0) && (collectable->x <= screen->w) &&
(collectable->y >= 0) && (collectable->y <= screen->h)) (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++) for (int i = 0 ; i < 10 ; i++)
addExplosion(collectable->x + rand() % 25 - rand() % 25, addExplosion(collectable->x + rand() % 25 - rand() % 25,
@ -448,9 +448,9 @@ void doCollectables()
{ {
setInfoLine(temp, FONT_WHITE); setInfoLine(temp, FONT_WHITE);
if (collectable->type == P_SHIELD) if (collectable->type == P_SHIELD)
playSound(SFX_SHIELDUP, player.x); audio_playSound(SFX_SHIELDUP, player.x);
else else
playSound(SFX_PICKUP, player.x); audio_playSound(SFX_PICKUP, player.x);
} }
} }

View File

@ -22,9 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void addDebris(int x, int y, int amount) void addDebris(int x, int y, int amount)
{ {
if ((rand() % 2) == 0) if ((rand() % 2) == 0)
playSound(SFX_DEBRIS, x); audio_playSound(SFX_DEBRIS, x);
else else
playSound(SFX_DEBRIS2, x); audio_playSound(SFX_DEBRIS2, x);
object *debris; object *debris;

View File

@ -86,7 +86,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MAX_WEAPONS 20 #define MAX_WEAPONS 20
#define MAX_SHAPES 100 #define MAX_SHAPES 100
#define MAX_SHIPSHAPES 120 #define MAX_SHIPSHAPES 120
#define MAX_SOUNDS 17
#define MAX_ALIENS 25 #define MAX_ALIENS 25
#define MAX_TEXTSHAPES 150 #define MAX_TEXTSHAPES 150
#define MAX_FONTSHAPES 6 #define MAX_FONTSHAPES 6
@ -339,7 +338,8 @@ enum {
SFX_DEBRIS2, SFX_DEBRIS2,
SFX_LASER, SFX_LASER,
SFX_PLASMA2, SFX_PLASMA2,
SFX_PLASMA3 SFX_PLASMA3,
SFX_MAX
}; };
enum { enum {

View File

@ -541,7 +541,7 @@ int mainGameLoop()
else if ((currentGame.area == 26) && (engine.musicVolume > 0)) else if ((currentGame.area == 26) && (engine.musicVolume > 0))
{ {
limitFloat(&(engine.musicVolume -= 0.2), 0, 100); limitFloat(&(engine.musicVolume -= 0.2), 0, 100);
Mix_VolumeMusic((int)engine.musicVolume); audio_setMusicVolume((int)engine.musicVolume);
} }
else else
{ {
@ -556,7 +556,7 @@ int mainGameLoop()
else else
{ {
limitFloat(&(engine.musicVolume -= 0.2), 0, 100); limitFloat(&(engine.musicVolume -= 0.2), 0, 100);
Mix_VolumeMusic((int)engine.musicVolume); audio_setMusicVolume((int)engine.musicVolume);
if (SDL_GetTicks() >= engine.missionCompleteTimer) if (SDL_GetTicks() >= engine.missionCompleteTimer)
{ {
engine.done = 1; engine.done = 1;
@ -721,7 +721,7 @@ int mainGameLoop()
alien->flags -= FL_ISCLOAKED; alien->flags -= FL_ISCLOAKED;
else else
alien->flags += FL_ISCLOAKED; alien->flags += FL_ISCLOAKED;
playSound(SFX_CLOAK, alien->x); audio_playSound(SFX_CLOAK, alien->x);
} }
if (alien->classDef == CD_BARRIER) if (alien->classDef == CD_BARRIER)
@ -780,7 +780,7 @@ int mainGameLoop()
(alien->ammo[0] == 250)) (alien->ammo[0] == 250))
{ {
alien->flags += FL_FIRERAY; 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 // specific to Boss 1
if ((currentGame.area == 5) && (aliens[WC_BOSS].flags & FL_ESCAPED)) 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); clearScreen(white);
updateScreen(); updateScreen();
for (int i = 0 ; i < 300 ; i++) for (int i = 0 ; i < 300 ; i++)
{ {
SDL_Delay(10); SDL_Delay(10);
if ((rand() % 25) == 0) if ((rand() % 25) == 0)
playSound(SFX_EXPLOSION, aliens[WC_BOSS].x); audio_playSound(SFX_EXPLOSION, aliens[WC_BOSS].x);
} }
SDL_Delay(1000); SDL_Delay(1000);
break; break;

View File

@ -224,7 +224,7 @@ void initSystem()
{ {
if (Mix_OpenAudio(44100, AUDIO_S16, engine.useAudio * 2, 1024) < 0) 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"); printf("Sound and Music will be disabled\n");
engine.useAudio = false; engine.useAudio = false;
} }
@ -246,7 +246,7 @@ void cleanUp()
{ {
freeGraphics(); freeGraphics();
SDL_FreeSurface(background); SDL_FreeSurface(background);
freeSound(); audio_free();
resetLists(); resetLists();
delete(engine.bulletHead); delete(engine.bulletHead);
delete(engine.explosionHead); delete(engine.explosionHead);

View File

@ -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)) if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 222, 45, 22))
{ {
engine.useMusic = true; engine.useMusic = true;
if (engine.useAudio) audio_playMusic("music/through_space.ogg", -1);
{
if (Mix_PausedMusic() == 1)
Mix_ResumeMusic();
else
Mix_PlayMusic(engine.music, -1);
}
} }
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22)) if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22))
{ {
engine.useMusic = false; engine.useMusic = false;
if (engine.useAudio) audio_haltMusic();
Mix_PauseMusic();
} }
if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22)) if (collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22))
@ -469,8 +462,6 @@ int galaxyMap()
initSaveSlots(); initSaveSlots();
loadMusic("music/through_space.ogg");
loadBackground(systemBackground[currentGame.system]); loadBackground(systemBackground[currentGame.system]);
char string[25]; char string[25];
@ -556,7 +547,7 @@ int galaxyMap()
int rtn = 0; int rtn = 0;
if ((engine.useAudio) && (engine.useMusic)) if ((engine.useAudio) && (engine.useMusic))
Mix_PlayMusic(engine.music, -1); audio_playMusic("music/through_space.ogg", -1);
textObject iconInfo[12]; textObject iconInfo[12];
@ -833,7 +824,7 @@ int galaxyMap()
delayFrame(); delayFrame();
} }
Mix_HaltMusic(); audio_haltMusic();
SDL_FreeSurface(statsSurface); SDL_FreeSurface(statsSurface);
SDL_FreeSurface(savesSurface); SDL_FreeSurface(savesSurface);
SDL_FreeSurface(optionsSurface); SDL_FreeSurface(optionsSurface);

View File

@ -235,7 +235,7 @@ void doInfo()
{ {
if ((engine.seconds > 1) && (engine.seconds <= 11) && (engine.minutes == 0)) if ((engine.seconds > 1) && (engine.seconds <= 11) && (engine.minutes == 0))
{ {
playSound(SFX_CLOCK); audio_playSound(SFX_CLOCK, screen->w / 2);
} }
if (engine.seconds > 0) if (engine.seconds > 0)

View File

@ -516,9 +516,7 @@ static char revealHiddenObjectives()
aliens[WC_KLINE].y = player.y; aliens[WC_KLINE].y = player.y;
aliens[WC_KLINE].flags |= FL_IMMORTAL | FL_NOFIRE; aliens[WC_KLINE].flags |= FL_IMMORTAL | FL_NOFIRE;
player_setTarget(WC_KLINE); player_setTarget(WC_KLINE);
loadMusic("music/last_cyber_dance.ogg"); audio_playMusic("music/last_cyber_dance.ogg", -1);
if ((engine.useAudio) && (engine.useMusic))
Mix_PlayMusic(engine.music, -1);
} }
} }
@ -789,7 +787,7 @@ void missionBriefScreen()
textSurface(11, "Power", 25, 570, FONT_WHITE); textSurface(11, "Power", 25, 570, FONT_WHITE);
textSurface(12, "Output", 250, 570, FONT_WHITE); textSurface(12, "Output", 250, 570, FONT_WHITE);
textSurface(13, "Cooler", 485, 570, FONT_WHITE); textSurface(13, "Cooler", 485, 570, FONT_WHITE);
playRandomTrack(); audio_playRandomTrack();
if (currentGame.area != MAX_MISSIONS - 1) if (currentGame.area != MAX_MISSIONS - 1)
{ {
@ -915,7 +913,7 @@ void missionFinishedScreen()
if (player.weaponType[1] == W_LASER) if (player.weaponType[1] == W_LASER)
player.ammo[1] = 1; player.ammo[1] = 1;
Mix_HaltMusic(); audio_haltMusic();
} }
/* /*

View File

@ -209,7 +209,7 @@ void doPlayer()
if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) && if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) &&
(currentMission.remainingObjectives1 == 0)) (currentMission.remainingObjectives1 == 0))
{ {
playSound(SFX_FLY); audio_playSound(SFX_FLY, screen->w / 2);
engine.done = 2; engine.done = 2;
engine.missionCompleteTimer = (SDL_GetTicks() - 1); engine.missionCompleteTimer = (SDL_GetTicks() - 1);
} }
@ -322,8 +322,8 @@ void doPlayer()
aliens[i].flags |= FL_LEAVESECTOR; aliens[i].flags |= FL_LEAVESECTOR;
} }
playSound(SFX_DEATH, player.x); audio_playSound(SFX_DEATH, player.x);
playSound(SFX_EXPLOSION, 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; 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) if (player.x <= -100)
{ {
engine.done = 2; engine.done = 2;
playSound(SFX_FLY); audio_playSound(SFX_FLY, screen->w / 2);
} }
} }

View File

@ -144,38 +144,6 @@ void loadGameGraphics()
setWeaponShapes(); 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 Custom loading to alter the font color before doing

View File

@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern void loadBackground(const char *filename); extern void loadBackground(const char *filename);
extern void loadGameGraphics(); extern void loadGameGraphics();
extern void loadSound();
extern void freeSound();
extern void loadFont(); extern void loadFont();
#endif #endif

View File

@ -244,8 +244,6 @@ struct globalEngineVariables {
float smx; float smx;
float smy; float smy;
Mix_Music *music;
object *bulletHead; object *bulletHead;
object *bulletTail; object *bulletTail;
object *explosionHead; object *explosionHead;

View File

@ -188,8 +188,6 @@ int doTitle()
signed char continueSaveSlot = initSaveSlots(); signed char continueSaveSlot = initSaveSlots();
loadMusic("music/walking_among_androids.ogg");
loadBackground("gfx/spirit.jpg"); loadBackground("gfx/spirit.jpg");
SDL_Surface *prlogo, *sflogo; SDL_Surface *prlogo, *sflogo;
@ -266,8 +264,7 @@ int doTitle()
flushInput(); flushInput();
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
if ((engine.useMusic) && (engine.useAudio)) audio_playMusic("music/walking_among_androids.ogg", 1);
Mix_PlayMusic(engine.music, 1);
while (!engine.done) while (!engine.done)
{ {
@ -467,14 +464,12 @@ int doTitle()
if (engine.useMusic) if (engine.useMusic)
{ {
if (Mix_PausedMusic() == 1) audio_playMusic(
Mix_ResumeMusic(); "music/walking_among_androids.ogg", 1);
else
Mix_PlayMusic(engine.music, 1);
} }
else else
{ {
Mix_PauseMusic(); audio_haltMusic();
} }
} }
else if (selectedOption == 3) else if (selectedOption == 3)
@ -521,7 +516,7 @@ int doTitle()
delayFrame(); delayFrame();
} }
Mix_HaltMusic(); audio_haltMusic();
SDL_FreeSurface(prlogo); SDL_FreeSurface(prlogo);
SDL_FreeSurface(sflogo); SDL_FreeSurface(sflogo);
@ -626,8 +621,6 @@ void gameover()
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
engine.gameSection = SECTION_INTERMISSION; engine.gameSection = SECTION_INTERMISSION;
loadMusic("music/death.ogg");
SDL_Surface *gameover = loadImage("gfx/gameover.png"); SDL_Surface *gameover = loadImage("gfx/gameover.png");
clearScreen(black); clearScreen(black);
@ -635,11 +628,7 @@ void gameover()
clearScreen(black); clearScreen(black);
SDL_Delay(1000); SDL_Delay(1000);
if ((engine.useMusic) && (engine.useAudio)) audio_playMusic("music/death.ogg", 1);
{
Mix_VolumeMusic(100);
Mix_PlayMusic(engine.music, 1);
}
int x = (screen->w - gameover->w) / 2; int x = (screen->w - gameover->w) / 2;
int y = (screen->h - gameover->h) / 2; int y = (screen->h - gameover->h) / 2;
@ -667,10 +656,7 @@ void gameover()
} }
SDL_FreeSurface(gameover); SDL_FreeSurface(gameover);
audio_haltMusic();
if ((engine.useMusic) && (engine.useAudio))
Mix_HaltMusic();
flushBuffer(); flushBuffer();
} }
@ -680,9 +666,6 @@ void doCredits()
flushBuffer(); flushBuffer();
freeGraphics(); freeGraphics();
if ((engine.useMusic) && (engine.useAudio))
loadMusic("music/rise_of_spirit.ogg");
FILE *fp; FILE *fp;
int lastCredit = -1; int lastCredit = -1;
@ -699,11 +682,7 @@ void doCredits()
drawBackGround(); drawBackGround();
if ((engine.useMusic) && (engine.useAudio)) audio_playMusic("music/rise_of_spirit.ogg", 1);
{
Mix_VolumeMusic(100);
Mix_PlayMusic(engine.music, 1);
}
fp = fopen("data/credits.txt", "rb"); fp = fopen("data/credits.txt", "rb");
// FIXME: It would be nice for the size of this array to be determined // FIXME: It would be nice for the size of this array to be determined