diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-11 20:54:12 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-01-11 20:54:12 +0100 |
commit | 94692dd2abd30d36175fb3cb5225e03787713820 (patch) | |
tree | 8c03227da5f1facc95bc15c5f895978f9b1f66f9 | |
parent | e0f98a1650a844a5941b5cb0c11a8097f86903cc (diff) | |
download | mana-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.
-rw-r--r-- | src/being.cpp | 17 | ||||
-rw-r--r-- | src/sound.cpp | 27 | ||||
-rw-r--r-- | src/sound.h | 4 |
3 files changed, 39 insertions, 9 deletions
diff --git a/src/being.cpp b/src/being.cpp index 570d8b22..4d682ab8 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -362,7 +362,18 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) if (amount > 0) { - sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + if (mInfo) + { + if (attacker) + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT), + attacker->getTileX(), attacker->getTileY()); + } + else + { + sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT)); + } + } if (getType() == MONSTER) { @@ -394,7 +405,7 @@ void Being::handleAttack(Being *victim, int damage, AttackType type) } 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) @@ -619,7 +630,7 @@ void Being::setAction(Action action, int attackType) break; case DEAD: currentAction = SpriteAction::DEAD; - 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 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); } } diff --git a/src/sound.h b/src/sound.h index bf5dc3f6..bfb3837b 100644 --- a/src/sound.h +++ b/src/sound.h @@ -86,8 +86,10 @@ class Sound * Plays an item. * * @param path The resource path to the sound file. + * @param x The vertical distance of the sound in tiles. + * @param y The horizontal distance of the sound in tiles. */ - void playSfx(const std::string &path); + void playSfx(const std::string &path, int x = 0, int y = 0); private: /** Logs various info about sound device. */ |