summaryrefslogtreecommitdiff
path: root/src/sound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound.cpp')
-rw-r--r--src/sound.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/sound.cpp b/src/sound.cpp
index fa39e49b..c64e10d8 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),
@@ -142,7 +142,7 @@ void Sound::setSfxVolume(int volume)
static Mix_Music *loadMusic(const std::string &filename)
{
ResourceManager *resman = ResourceManager::getInstance();
- std::string path = resman->getPath("music/" + filename);
+ std::string path = resman->getPath(paths.getStringValue("music") + filename);
if (path.find(".zip/") != std::string::npos ||
path.find(".zip\\") != std::string::npos)
@@ -152,7 +152,7 @@ static Mix_Music *loadMusic(const std::string &filename)
logger->log("Loading music \"%s\" from temporary file tempMusic.ogg",
path.c_str());
bool success = resman->copyFile(
- paths.getValue("music", "music/")
+ paths.getStringValue("music")
+ filename, "tempMusic.ogg");
if (success)
path = resman->getPath("tempMusic.ogg");
@@ -228,17 +228,38 @@ 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;
+
+ // Check for negative values
+ if (dist * 8 > vol)
+ return;
+ vol -= dist * 8;
+ }
+ sample->play(0, vol);
}
}