summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp2
-rw-r--r--src/localplayer.cpp9
-rw-r--r--src/sound.cpp30
3 files changed, 17 insertions, 24 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 9483e897..2f904d08 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -376,7 +376,7 @@ void Being::takeDamage(Being *attacker, int amount,
if (attacker)
{
sound.playSfx(mInfo->getSound(SOUND_EVENT_HURT),
- attacker->getTileX(), attacker->getTileY());
+ attacker->getPixelX(), attacker->getPixelY());
}
else
{
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 28f26755..a0350ce8 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -599,10 +599,8 @@ void LocalPlayer::pickUp(FloorItem *item)
if (!item)
return;
- int tileWidth = mMap->getTileWidth();
- int tileHeight = mMap->getTileHeight();
- int dx = item->getTileX() - (int) getPosition().x / tileWidth;
- int dy = item->getTileY() - ((int) getPosition().y - 1) / tileHeight;
+ int dx = item->getTileX() - getTileX();
+ int dy = item->getTileY() - getTileY();
if (dx * dx + dy * dy < 4)
{
@@ -612,8 +610,7 @@ void LocalPlayer::pickUp(FloorItem *item)
else
{
pathSetByMouse();
- setDestination(item->getTileX() * tileWidth + tileWidth / 2,
- item->getTileY() * tileHeight + tileHeight / 2);
+ setDestination(item->getPixelX(), item->getPixelY());
mPickUpTarget = item;
}
}
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);
}
}