summaryrefslogtreecommitdiff
path: root/src/sound.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-11 20:54:12 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-11 20:54:12 +0100
commit94692dd2abd30d36175fb3cb5225e03787713820 (patch)
tree8c03227da5f1facc95bc15c5f895978f9b1f66f9 /src/sound.cpp
parente0f98a1650a844a5941b5cb0c11a8097f86903cc (diff)
downloadmana-94692dd2abd30d36175fb3cb5225e03787713820.tar.gz
mana-94692dd2abd30d36175fb3cb5225e03787713820.tar.bz2
mana-94692dd2abd30d36175fb3cb5225e03787713820.tar.xz
mana-94692dd2abd30d36175fb3cb5225e03787713820.zip
Added a distance based positional sfx sound system. Thanks to 4144.
Based on: http://gitorious.org/manaplus/manaplus/commit/ef7f53e43ce4306080efae3b86443a6016a3e66a Resolves: TMW-Mantis #536 Reviewed-by: 4144.
Diffstat (limited to 'src/sound.cpp')
-rw-r--r--src/sound.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/sound.cpp b/src/sound.cpp
index 6fe9668d..a8090f84 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -21,14 +21,14 @@
#include <SDL.h>
+#include "configuration.h"
+#include "localplayer.h"
#include "log.h"
#include "sound.h"
#include "resources/resourcemanager.h"
#include "resources/soundeffect.h"
-#include "configuration.h"
-
Sound::Sound():
mInstalled(false),
mSfxVolume(100),
@@ -228,17 +228,34 @@ void Sound::fadeOutMusic(int ms)
}
}
-void Sound::playSfx(const std::string &path)
+void Sound::playSfx(const std::string &path, int x, int y)
{
if (!mInstalled || path.empty())
return;
+ std::string tmpPath;
+ if (!path.find("sfx/"))
+ tmpPath = path;
+ else
+ tmpPath = paths.getValue("sfx", "sfx/") + path;
ResourceManager *resman = ResourceManager::getInstance();
- SoundEffect *sample = resman->getSoundEffect(path);
+ SoundEffect *sample = resman->getSoundEffect(tmpPath);
if (sample)
{
logger->log("Sound::playSfx() Playing: %s", path.c_str());
- sample->play(0, 120);
+ int vol = 120;
+ if (player_node && x > 0 && y > 0)
+ {
+ int dx = player_node->getTileX() - x;
+ int dy = player_node->getTileY() - y;
+ if (dx < 0)
+ dx = -dx;
+ if (dy < 0)
+ dy = -dy;
+ int dist = dx > dy ? dx : dy;
+ vol -= dist * 8;
+ }
+ sample->play(0, vol);
}
}