summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-01-06 21:25:25 +0200
committerAndrei Karas <akaras@inbox.ru>2011-01-06 21:32:01 +0200
commitef7f53e43ce4306080efae3b86443a6016a3e66a (patch)
tree64dcb0229a5d0a5e75c77712743748d8a374e6a0
parent61f8436a6ea04fcdede91ca26ebec6d558ac5cd0 (diff)
downloadmv-ef7f53e43ce4306080efae3b86443a6016a3e66a.tar.gz
mv-ef7f53e43ce4306080efae3b86443a6016a3e66a.tar.bz2
mv-ef7f53e43ce4306080efae3b86443a6016a3e66a.tar.xz
mv-ef7f53e43ce4306080efae3b86443a6016a3e66a.zip
Set sound volume depends on distance to object.
-rw-r--r--src/being.cpp14
-rw-r--r--src/sound.cpp32
-rw-r--r--src/sound.h2
3 files changed, 45 insertions, 3 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 2372cfe1b..1d8178670 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -568,7 +568,15 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type)
mDamageTaken += amount;
if (mInfo)
{
- sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT));
+ if (attacker)
+ {
+ sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT),
+ attacker->getTileX(), attacker->getTileY());
+ }
+ else
+ {
+ sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT));
+ }
if (!mInfo->isStaticMaxHP())
{
if (!mHP && mInfo->getMaxHP() < mDamageTaken)
@@ -618,7 +626,7 @@ void Being::handleAttack(Being *victim, int damage,
}
sound.playSfx(mInfo->getSound((damage > 0) ?
- SOUND_EVENT_HIT : SOUND_EVENT_MISS));
+ SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY);
}
void Being::setName(const std::string &name)
@@ -904,7 +912,7 @@ void Being::setAction(Action action, int attackType _UNUSED_)
case DEAD:
currentAction = SpriteAction::DEAD;
if (mInfo)
- sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE));
+ sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE), mX, mY);
break;
case STAND:
currentAction = SpriteAction::STAND;
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)
diff --git a/src/sound.h b/src/sound.h
index 100c228c1..92c0ab41a 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -93,6 +93,8 @@ class Sound : public ConfigListener
*/
void playSfx(const std::string &path);
+ void playSfx(const std::string &path, int x, int y);
+
/**
* Plays an item for gui.
*