Positional battle sounds. Record player's last position when escaped, to allow for sounds to play correctly (edge case).
This commit is contained in:
parent
d703da7d23
commit
e5565c0370
|
@ -78,11 +78,10 @@ void playSound(int id)
|
|||
|
||||
void playBattleSound(int id, int x, int y)
|
||||
{
|
||||
float distance;
|
||||
float distance, bearing, vol;
|
||||
int channel;
|
||||
float vol;
|
||||
|
||||
if (player->alive == ALIVE_ALIVE)
|
||||
if (player->alive == ALIVE_ALIVE || player->alive == ALIVE_ESCAPED)
|
||||
{
|
||||
lastPlayerX = player->x;
|
||||
lastPlayerY = player->y;
|
||||
|
@ -93,16 +92,25 @@ void playBattleSound(int id, int x, int y)
|
|||
if (distance <= MAX_BATTLE_SOUND_DISTANCE)
|
||||
{
|
||||
channel = Mix_PlayChannel(-1, sounds[id], 0);
|
||||
|
||||
if (channel != -1)
|
||||
{
|
||||
vol = 255;
|
||||
vol /= MAX_BATTLE_SOUND_DISTANCE;
|
||||
vol *= distance;
|
||||
|
||||
if (distance >= MIN_BATTLE_SOUND_DISTANCE)
|
||||
{
|
||||
bearing = 360 - getAngle(x, y, lastPlayerX, lastPlayerY);
|
||||
Mix_SetPosition(channel, (Sint16)bearing, (Uint8)vol);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mix_SetDistance(channel, vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Mix_Chunk *loadSound(char *filename)
|
||||
{
|
||||
|
|
|
@ -23,8 +23,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "SDL2/SDL_mixer.h"
|
||||
|
||||
#define MAX_BATTLE_SOUND_DISTANCE 1500
|
||||
#define MIN_BATTLE_SOUND_DISTANCE 100
|
||||
|
||||
extern int getDistance(int x1, int y1, int x2, int y2);
|
||||
extern float getAngle(int x1, int y1, int x2, int y2);
|
||||
extern char *getFileLocation(char *filename);
|
||||
|
||||
extern Entity *player;
|
||||
|
|
Loading…
Reference in New Issue