diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-19 23:15:45 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-20 19:46:11 +0100 |
commit | 64cec0656a7df985304b45b83c380911af44c726 (patch) | |
tree | 50227c17d6846f9214f1d30c250dc8df9fe4bee5 /src/sound.cpp | |
parent | db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e (diff) | |
download | mana-64cec0656a7df985304b45b83c380911af44c726.tar.gz mana-64cec0656a7df985304b45b83c380911af44c726.tar.bz2 mana-64cec0656a7df985304b45b83c380911af44c726.tar.xz mana-64cec0656a7df985304b45b83c380911af44c726.zip |
Fixed a bug with hurt sounds volume and simplified code
The hurt sound volume was being played based on the distance in tiles,
even though Sound::playSfx was expecting pixels. This would cause
hurt sounds of other players to play too loud.
There were also several conversions between pixel and tile coordinates
that could be simplified.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/sound.cpp')
-rw-r--r-- | src/sound.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/sound.cpp b/src/sound.cpp index 6248d247..468f48c0 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -284,29 +284,25 @@ void Sound::playSfx(const std::string &path, int x, int y) tmpPath = path; else tmpPath = paths.getValue("sfx", "sfx/") + path; + ResourceManager *resman = ResourceManager::getInstance(); - SoundEffect *sample = resman->getSoundEffect(tmpPath); - if (sample) + + if (SoundEffect *sample = resman->getSoundEffect(tmpPath)) { logger->log("Sound::playSfx() Playing: %s", path.c_str()); int vol = 120; - if (local_player && x > 0 && y > 0) + + if (local_player && (x > 0 || y > 0)) { - Vector pos = local_player->getPosition(); - Map *map = Game::instance()->getCurrentMap(); - int dx = ((int)pos.x - x) / map->getTileWidth(); - int dy = ((int)pos.y - y) / map->getTileHeight(); - 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; + const Vector &pos = local_player->getPosition(); + const int dx = std::abs((int) pos.x - x); + const int dy = std::abs((int) pos.y - y); + const int dist = std::max(dx, dy); + + // Volume goes down one level with each 4 pixels + vol -= std::min(120, dist / 4); } + sample->play(0, vol); } } |