Positional battle audio

This commit is contained in:
Cong 2017-05-16 00:06:07 +10:00
parent 081cc142ee
commit 178153c82b
2 changed files with 11 additions and 1 deletions

View File

@ -99,7 +99,15 @@ void playBattleSound(int id, int x, int y)
vol /= MAX_BATTLE_SOUND_DISTANCE;
vol *= distance;
Mix_SetDistance(channel, vol);
if (distance >= MIN_BATTLE_SOUND_DISTANCE)
{
float bearing = 360 - getAngle(x, y, lastPlayerX, lastPlayerY);
Mix_SetPosition(channel, (Sint16)bearing, (Uint8)distance);
}
else
{
Mix_SetDistance(channel, vol);
}
}
}
}

View File

@ -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;