2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012 Guus Sliepen
|
|
|
|
Copyright (C) 2015 Julian Marchant
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
#include "Starfighter.h"
|
|
|
|
|
|
|
|
Mix_Chunk *sound[MAX_SOUNDS];
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2012-03-02 23:00:35 +01:00
|
|
|
void playSound(int sid, float x)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2011-08-26 22:48:52 +02:00
|
|
|
if ((!engine.useSound) || (!engine.useAudio))
|
2011-08-24 14:14:44 +02:00
|
|
|
return;
|
|
|
|
|
2012-03-11 15:11:15 +01:00
|
|
|
int channel = -1;
|
2012-03-02 23:00:35 +01:00
|
|
|
static int freechannel = 4;
|
|
|
|
|
2011-08-24 14:14:44 +02:00
|
|
|
switch(sid)
|
|
|
|
{
|
|
|
|
case SFX_DEATH:
|
|
|
|
case SFX_CLOCK:
|
|
|
|
case SFX_FLY:
|
|
|
|
case SFX_SHIELDUP:
|
|
|
|
case SFX_PICKUP:
|
|
|
|
case SFX_CLOAK:
|
|
|
|
case SFX_PLASMA2:
|
|
|
|
case SFX_PLASMA3:
|
2012-03-02 23:00:35 +01:00
|
|
|
channel = -1;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case SFX_PLASMA:
|
|
|
|
case SFX_LASER:
|
2012-03-02 23:00:35 +01:00
|
|
|
channel = 0;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case SFX_ENERGYRAY:
|
|
|
|
case SFX_MISSILE:
|
2012-03-02 23:00:35 +01:00
|
|
|
channel = 1;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case SFX_HIT:
|
2012-03-02 23:00:35 +01:00
|
|
|
channel = 2;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case SFX_EXPLOSION:
|
|
|
|
case SFX_DEBRIS:
|
|
|
|
case SFX_DEBRIS2:
|
2012-03-02 23:00:35 +01:00
|
|
|
channel = 3;
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-03-02 23:00:35 +01:00
|
|
|
|
|
|
|
if(channel == -1) {
|
|
|
|
channel = freechannel++;
|
|
|
|
if(freechannel >= 8)
|
|
|
|
freechannel = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
int angle = atanf((x - 400) / 400) * 180 / M_PI;
|
|
|
|
int attenuation = fabsf(x - 400) / 40;
|
|
|
|
|
|
|
|
if(angle < 0)
|
|
|
|
angle += 360;
|
|
|
|
|
|
|
|
if(attenuation > 255)
|
|
|
|
attenuation = 255;
|
|
|
|
|
|
|
|
Mix_SetPosition(channel, angle, attenuation);
|
|
|
|
Mix_PlayChannel(channel, sound[sid], 0);
|
2011-08-24 14:14:44 +02:00
|
|
|
}
|
|
|
|
|
2011-08-24 14:42:59 +02:00
|
|
|
Mix_Chunk *loadSound(const char *filename)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
Mix_Chunk *chunk;
|
|
|
|
|
|
|
|
chunk = Mix_LoadWAV(filename);
|
|
|
|
|
|
|
|
return chunk;
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:42:59 +02:00
|
|
|
void loadMusic(const char *filename)
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
|
|
|
if (Mix_PlayingMusic())
|
|
|
|
Mix_HaltMusic();
|
|
|
|
|
|
|
|
if (engine.music != NULL)
|
|
|
|
Mix_FreeMusic(engine.music);
|
|
|
|
|
|
|
|
engine.music = Mix_LoadMUS(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void playRandomTrack()
|
|
|
|
{
|
2011-08-26 22:48:52 +02:00
|
|
|
if ((!engine.useMusic) || (!engine.useAudio))
|
2011-08-24 14:14:44 +02:00
|
|
|
return;
|
|
|
|
|
2015-02-27 04:30:26 +01:00
|
|
|
int tracks = 3;
|
2015-02-26 20:18:27 +01:00
|
|
|
char track[][64] = {
|
2015-02-27 04:30:26 +01:00
|
|
|
"music/railjet_short.ogg", "music/space_dimensions.ogg",
|
|
|
|
"music/frozen_jam.ogg"
|
2011-08-24 14:14:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
switch(currentGame.area)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
case 11:
|
|
|
|
case 18:
|
|
|
|
case 25:
|
2015-02-26 21:52:18 +01:00
|
|
|
loadMusic("music/orbital_colossus.ogg");
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
case 26:
|
2015-02-26 20:18:27 +01:00
|
|
|
loadMusic("music/RE.ogg");
|
2011-08-24 14:14:44 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
loadMusic(track[rand() % tracks]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Mix_PlayMusic(engine.music, -1);
|
|
|
|
}
|