Added a Y component to audio_playSound, and reduction of volume by distance.

This makes it possible to remove code that made mines that exploded
off-screen completely inaudible.
This commit is contained in:
onpon4 2016-01-10 23:56:26 -05:00
parent 5ba8759804
commit 0929abf3a3
7 changed files with 46 additions and 45 deletions

View File

@ -1643,7 +1643,7 @@ void alien_move(object *alien)
alien->hit = 3;
alien->dx *= -1;
alien->dy *= -1;
audio_playSound(SFX_HIT, alien->x);
audio_playSound(SFX_HIT, alien->x, alien->y);
}
}
}
@ -1659,9 +1659,9 @@ void alien_move(object *alien)
if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0))
player.shield -= alien->shield;
alien->shield = 0;
audio_playSound(SFX_EXPLOSION, alien->x);
audio_playSound(SFX_EXPLOSION, alien->x, alien->y);
player.hit = 5;
audio_playSound(SFX_HIT, player.x);
audio_playSound(SFX_HIT, player.x, player.y);
}
if (alien->classDef == CD_ASTEROID2)
@ -1669,9 +1669,9 @@ void alien_move(object *alien)
if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0))
player.shield -= alien->shield;
alien->shield = 0;
audio_playSound(SFX_EXPLOSION, alien->x);
audio_playSound(SFX_EXPLOSION, alien->x, alien->y);
player.hit = 5;
audio_playSound(SFX_HIT, player.x);
audio_playSound(SFX_HIT, player.x, player.y);
}
if (alien->classDef == CD_BARRIER)
@ -1679,7 +1679,7 @@ void alien_move(object *alien)
if ((!engine.cheatShield) && (engine.missionCompleteTimer == 0))
player.shield--;
player.hit = 5;
audio_playSound(SFX_HIT, player.x);
audio_playSound(SFX_HIT, player.x, player.y);
}
}
}
@ -1690,7 +1690,7 @@ Fill in later...
*/
void alien_destroy(object *alien, object *attacker)
{
audio_playSound(SFX_EXPLOSION, alien->x);
audio_playSound(SFX_EXPLOSION, alien->x, alien->y);
if (alien->flags & FL_FRIEND)
{
@ -1841,7 +1841,7 @@ void alien_hurt(object *alien, object *attacker, int damage, bool ion)
alien->flags |= FL_LEAVESECTOR;
}
audio_playSound(SFX_HIT, alien->x);
audio_playSound(SFX_HIT, alien->x, alien->y);
if (alien->AIType == AI_EVASIVE)
alien->thinktime = 0;

View File

@ -42,13 +42,17 @@ void audio_loadSounds()
sound[SFX_PLASMA3] = Mix_LoadWAV("sound/plasma3.ogg");
}
void audio_playSound(int sid, float x)
void audio_playSound(int sid, float x, float y)
{
if ((!engine.useSound) || (!engine.useAudio))
return;
int channel = -1;
static int freechannel = 4;
int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI;
int attenuation = fabsf(x - (screen->w / 2)) / (screen->w / 20);
float distance = sqrtf(powf(fabsf(x - (screen->w / 2)), 2) + powf(fabsf(y - (screen->h / 2)), 2));
int volume = MIX_MAX_VOLUME - (MIX_MAX_VOLUME * distance / (3 * screen->w));
if ((!engine.useSound) || (!engine.useAudio) || (volume <= 0))
return;
switch(sid)
{
@ -86,9 +90,7 @@ void audio_playSound(int sid, float x)
freechannel = 4;
}
int angle = atanf((x - (screen->w / 2)) / (screen->w / 2)) * 180 / M_PI;
int attenuation = fabsf(x - (screen->w / 2)) / 40;
angle %= 360;
if (angle < 0)
angle += 360;
@ -96,6 +98,7 @@ void audio_playSound(int sid, float x)
attenuation = 255;
Mix_SetPosition(channel, angle, attenuation);
Mix_Volume(channel, volume);
Mix_PlayChannel(channel, sound[sid], 0);
}

View File

@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define AUDIO_H
void audio_loadSounds();
void audio_playSound(int sid, float x);
void audio_playSound(int sid, float x, float y);
void audio_haltMusic();
void audio_pauseMusic();
void audio_resumeMusic();

View File

@ -229,9 +229,7 @@ bool collectable_collision(collectables *collectable, object *ship)
void collectable_explode(collectables *collectable)
{
if ((collectable->x >= 0) && (collectable->x <= screen->w) &&
(collectable->y >= 0) && (collectable->y <= screen->h))
audio_playSound(SFX_EXPLOSION, collectable->x);
audio_playSound(SFX_EXPLOSION, collectable->x, collectable->y);
for (int i = 0 ; i < 10 ; i++)
explosion_add(RANDRANGE(collectable->x - 25, collectable->x + 25),

View File

@ -143,9 +143,9 @@ void game_init()
static void game_addDebris(int x, int y, int amount)
{
if ((rand() % 2) == 0)
audio_playSound(SFX_DEBRIS, x);
audio_playSound(SFX_DEBRIS, x, y);
else
audio_playSound(SFX_DEBRIS2, x);
audio_playSound(SFX_DEBRIS2, x, y);
object *debris;
@ -450,9 +450,9 @@ static void game_doCollectables()
{
setInfoLine(temp, FONT_WHITE);
if (collectable->type == P_SHIELD)
audio_playSound(SFX_SHIELDUP, player.x);
audio_playSound(SFX_SHIELDUP, player.x, player.y);
else
audio_playSound(SFX_PICKUP, player.x);
audio_playSound(SFX_PICKUP, player.x, player.y);
}
}
@ -648,7 +648,7 @@ static void game_doBullets()
{
bullet->active = false;
bullet->shield = 0;
audio_playSound(SFX_EXPLOSION, bullet->x);
audio_playSound(SFX_EXPLOSION, bullet->x, bullet->y);
for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35),
@ -700,7 +700,7 @@ static void game_doBullets()
{
bullet->active = false;
bullet->shield = 0;
audio_playSound(SFX_EXPLOSION, bullet->x);
audio_playSound(SFX_EXPLOSION, bullet->x, bullet->y);
for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35), SP_BIG_EXPLOSION);
@ -712,7 +712,7 @@ static void game_doBullets()
bullet->shield = 0;
}
audio_playSound(SFX_HIT, player.x);
audio_playSound(SFX_HIT, player.x, player.y);
if (bullet->id == WT_ROCKET)
explosion_add(bullet->x, bullet->y, SP_BIG_EXPLOSION);
@ -733,11 +733,11 @@ static void game_doBullets()
{
bullet->active = false;
explosion_add(bullet->x, bullet->y, SP_SMALL_EXPLOSION);
audio_playSound(SFX_HIT, cargo[j].x);
audio_playSound(SFX_HIT, cargo[j].x, cargo[j].y);
if (cargo[j].collectType != P_PHOEBE)
{
cargo[j].active = false;
audio_playSound(SFX_EXPLOSION, cargo[j].x);
audio_playSound(SFX_EXPLOSION, cargo[j].x, cargo[j].y);
for (int i = 0 ; i < 10 ; i++)
explosion_add(cargo[j].x + RANDRANGE(-15, 15),
cargo[j].y + RANDRANGE(-15, 15),
@ -803,7 +803,7 @@ static void game_doBullets()
{
if (bullet->flags & WF_TIMEDEXPLOSION)
{
audio_playSound(SFX_EXPLOSION, bullet->x);
audio_playSound(SFX_EXPLOSION, bullet->x, bullet->y);
for (int i = 0 ; i < 10 ; i++)
explosion_add(bullet->x + RANDRANGE(-35, 35),
bullet->y + RANDRANGE(-35, 35), SP_BIG_EXPLOSION);
@ -987,7 +987,7 @@ static void game_doAliens()
aliens[i].flags -= FL_ISCLOAKED;
else
aliens[i].flags += FL_ISCLOAKED;
audio_playSound(SFX_CLOAK, aliens[i].x);
audio_playSound(SFX_CLOAK, aliens[i].x, aliens[i].y);
}
if (aliens[i].classDef == CD_BARRIER)
@ -1046,7 +1046,7 @@ static void game_doAliens()
(aliens[i].ammo[0] >= 250))
{
aliens[i].flags += FL_FIRERAY;
audio_playSound(SFX_ENERGYRAY, aliens[i].x);
audio_playSound(SFX_ENERGYRAY, aliens[i].x, aliens[i].y);
}
}
}
@ -1306,7 +1306,7 @@ static void game_doPlayer()
if ((engine.done == 0) && (engine.gameSection == SECTION_GAME) &&
(currentMission.remainingObjectives1 == 0))
{
audio_playSound(SFX_FLY, screen->w / 2);
audio_playSound(SFX_FLY, screen->w / 2, screen->h / 2);
engine.done = 2;
engine.missionCompleteTimer = (SDL_GetTicks() - 1);
}
@ -1431,8 +1431,8 @@ static void game_doPlayer()
aliens[i].flags |= FL_LEAVESECTOR;
}
audio_playSound(SFX_DEATH, player.x);
audio_playSound(SFX_EXPLOSION, player.x);
audio_playSound(SFX_DEATH, player.x, player.y);
audio_playSound(SFX_EXPLOSION, player.x, player.y);
}
engine.keyState[KEY_UP] = engine.keyState[KEY_DOWN] = engine.keyState[KEY_LEFT] = engine.keyState[KEY_RIGHT] = 0;
@ -1754,7 +1754,7 @@ static void game_doHud()
{
if ((engine.seconds > 1) && (engine.seconds <= 11) && (engine.minutes == 0))
{
audio_playSound(SFX_CLOCK, screen->w / 2);
audio_playSound(SFX_CLOCK, screen->w / 2, screen->h / 2);
}
if (engine.seconds > 0)
@ -2333,14 +2333,14 @@ int game_mainLoop()
if ((game.area == MISN_MOEBO) &&
(aliens[ALIEN_BOSS].flags & FL_ESCAPED))
{
audio_playSound(SFX_DEATH, aliens[ALIEN_BOSS].x);
audio_playSound(SFX_DEATH, aliens[ALIEN_BOSS].x, aliens[ALIEN_BOSS].y);
screen_clear(white);
renderer_update();
for (int i = 0 ; i < 300 ; i++)
{
SDL_Delay(10);
if ((rand() % 25) == 0)
audio_playSound(SFX_EXPLOSION, aliens[ALIEN_BOSS].x);
audio_playSound(SFX_EXPLOSION, aliens[ALIEN_BOSS].x, aliens[ALIEN_BOSS].y);
}
SDL_Delay(1000);
break;

View File

@ -320,7 +320,7 @@ void leaveSector()
if (player.x <= -100)
{
engine.done = 2;
audio_playSound(SFX_FLY, screen->w / 2);
audio_playSound(SFX_FLY, screen->w / 2, screen->h / 2);
}
}

View File

@ -61,16 +61,16 @@ void ship_fireBullet(object *ship, int weaponType)
case WT_PLASMA:
case WT_SPREAD:
case WT_DIRECTIONAL:
audio_playSound(SFX_PLASMA, ship->x);
audio_playSound(SFX_PLASMA, ship->x, ship->y);
break;
case WT_ROCKET:
audio_playSound(SFX_MISSILE, ship->x);
audio_playSound(SFX_MISSILE, ship->x, ship->y);
break;
case WT_LASER:
audio_playSound(SFX_LASER, ship->x);
audio_playSound(SFX_LASER, ship->x, ship->y);
break;
case WT_CHARGER:
audio_playSound(SFX_PLASMA3, ship->x);
audio_playSound(SFX_PLASMA3, ship->x, ship->y);
break;
}
@ -177,11 +177,11 @@ void ship_fireRay(object *ship)
player.shield--;
explosion_add(player.x, player.y, SP_SMALL_EXPLOSION);
audio_playSound(SFX_HIT, player.x);
audio_playSound(SFX_HIT, player.x, player.y);
if (player.shield < 1)
{
audio_playSound(SFX_DEATH, player.x);
audio_playSound(SFX_EXPLOSION, player.x);
audio_playSound(SFX_DEATH, player.x, player.y);
audio_playSound(SFX_EXPLOSION, player.x, player.y);
}
}
}