summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-13 16:41:34 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-13 16:41:34 +0200
commit6c885855b0c06bd7c4b6ab3574d8e2f3398ad97a (patch)
treeb4371bafbfc998960fcfe7bae64b845ca1b2741f
parenteb201e566677f5ae55d1c443aa4254b99cec9e3e (diff)
downloadplus-6c885855b0c06bd7c4b6ab3574d8e2f3398ad97a.tar.gz
plus-6c885855b0c06bd7c4b6ab3574d8e2f3398ad97a.tar.bz2
plus-6c885855b0c06bd7c4b6ab3574d8e2f3398ad97a.tar.xz
plus-6c885855b0c06bd7c4b6ab3574d8e2f3398ad97a.zip
Remove playSfx duplicate function and add check for negative volume.
-rw-r--r--src/sound.cpp24
-rw-r--r--src/sound.h4
2 files changed, 5 insertions, 23 deletions
diff --git a/src/sound.cpp b/src/sound.cpp
index 080426a39..d71536cf2 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -262,25 +262,6 @@ void Sound::fadeOutMusic(int ms)
}
}
-void Sound::playSfx(const std::string &path)
-{
- 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());
- sample->play(0, 120);
- }
-}
-
void Sound::playSfx(const std::string &path, int x, int y)
{
if (!mInstalled || path.empty() || !mPlayBattle)
@@ -297,7 +278,7 @@ void Sound::playSfx(const std::string &path, int x, int y)
{
logger->log("Sound::playSfx() Playing: %s", path.c_str());
int vol = 120;
- if (player_node)
+ if (player_node && (x > 0 || y > 0))
{
int dx = player_node->getTileX() - x;
int dy = player_node->getTileY() - y;
@@ -306,6 +287,9 @@ void Sound::playSfx(const std::string &path, int x, int y)
if (dy < 0)
dy = -dy;
int dist = dx > dy ? dx : dy;
+ if (dist * 8 > vol)
+ return;
+
vol -= dist * 8;
}
sample->play(0, vol);
diff --git a/src/sound.h b/src/sound.h
index 92c0ab41a..de34a48f0 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -91,9 +91,7 @@ class Sound : public ConfigListener
*
* @param path The resource path to the sound file.
*/
- void playSfx(const std::string &path);
-
- void playSfx(const std::string &path, int x, int y);
+ void playSfx(const std::string &path, int x = 0, int y = 0);
/**
* Plays an item for gui.