]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/CAudio.cpp
Added .gitignore to ignore certain files + fixed access rights on Makefile* as
[quix0rs-blobwars.git] / src / CAudio.cpp
index 40af208fc2b2966ab985451364dafe3cf433f3cb..c713aaa396d25d921cec4be4210e5842c43ba254 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright (C) 2004-2010 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -110,8 +111,6 @@ bool Audio::loadMusic(const char *filename)
 
        remove(tempPath);
        
-       SDL_Delay(250); // wait a bit, just to be sure!
-
        if (music != NULL)
        {
                Mix_HaltMusic();
@@ -138,7 +137,15 @@ bool Audio::loadMusic(const char *filename)
                return false;
        }
 
-       snprintf(tempPath, sizeof tempPath, "%s.tags", filename);
+       #if USEPAK
+               snprintf(tempPath, sizeof tempPath, "%smusic.tags", engine->userHomeDirectory);
+               remove(tempPath);
+               char tagfilename[PATH_MAX];
+               snprintf(tagfilename, sizeof tagfilename, "%s.tags", filename);
+               engine->unpack(tagfilename, PAK_TAGS);
+       #else
+               snprintf(tempPath, sizeof tempPath, "%s.tags", filename);
+       #endif
        FILE *fp = fopen(tempPath, "r");
        char line[1024];
        
@@ -171,7 +178,7 @@ bool Audio::loadMusic(const char *filename)
        return true;
 }
 
-void Audio::playSound(int snd, int channel)
+void Audio::playSoundRelative(int snd, int channel, float x)
 {
        if ((!engine->useAudio) || (soundVolume == 0))
                return;
@@ -181,9 +188,29 @@ void Audio::playSound(int snd, int channel)
                return;
        }
 
-       Mix_Volume(channel, soundVolume);
+       int angle = atanf(x / 480) * 180 / M_PI;
+       int attenuation = fabsf(x) / 40;
+
+       if (angle < 0)
+               angle += 360;
+
+       if (attenuation > 255)
+               attenuation = 255;
 
+       Mix_Volume(channel, soundVolume);
        Mix_PlayChannel(channel, sound[snd], 0);
+       Mix_SetPosition(channel, angle, attenuation);
+}
+
+void Audio::playSound(int snd, int channel, float x)
+{
+       x -= (engine->playerPosX + 320);
+       playSoundRelative(snd, channel, x);
+}
+
+void Audio::playSound(int snd, int channel)
+{
+       playSoundRelative(snd, channel, 0);
 }
 
 void Audio::playMusic()