diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-01-11 01:34:11 +0200 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-01-11 01:34:11 +0200 |
commit | fcced13d9972ac70f0f01f19583b7868e255b6a7 (patch) | |
tree | 9b01df102c5f9ba032ea0f9bc413dd707e99d88b /src/sound.cpp | |
parent | 311783bebbe2bed366dca5097697ce34c690292d (diff) | |
parent | ef1b9856c86512fe73154c17da3ea98a7cd5f896 (diff) | |
download | plus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.gz plus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.bz2 plus-fcced13d9972ac70f0f01f19583b7868e255b6a7.tar.xz plus-fcced13d9972ac70f0f01f19583b7868e255b6a7.zip |
Merge branch 'master' into invfiler
Diffstat (limited to 'src/sound.cpp')
-rw-r--r-- | src/sound.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/sound.cpp b/src/sound.cpp index 8742ce361..080426a39 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -22,6 +22,7 @@ #include <SDL.h> #include "configuration.h" +#include "localplayer.h" #include "log.h" #include "sound.h" @@ -280,6 +281,37 @@ void Sound::playSfx(const std::string &path) } } +void Sound::playSfx(const std::string &path, int x, int y) +{ + if (!mInstalled || path.empty() || !mPlayBattle) + 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(tmpPath); + if (sample) + { + logger->log("Sound::playSfx() Playing: %s", path.c_str()); + int vol = 120; + if (player_node) + { + 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); + } +} + void Sound::playGuiSfx(const std::string &path) { if (!mInstalled || path.empty() || !mPlayGui) |