diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-02-17 19:48:04 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-02-17 20:36:22 +0100 |
commit | 1444d389cf841a0df151c387fab8296fe8866bf7 (patch) | |
tree | 15a93da1d2a3d906c0e6abb22acda85914fbafc2 | |
parent | f1897991c5f7da526e7c25dcc7f2f14182f01bf2 (diff) | |
download | Mana-1444d389cf841a0df151c387fab8296fe8866bf7.tar.gz Mana-1444d389cf841a0df151c387fab8296fe8866bf7.tar.bz2 Mana-1444d389cf841a0df151c387fab8296fe8866bf7.tar.xz Mana-1444d389cf841a0df151c387fab8296fe8866bf7.zip |
Fixed selecting of beings that are flanked between two others
Before it was a bit tricky to select the a being if there are two others around.
I fixed this by going through all sprites and looking for the closest one to the
mouse.
Reviewed-by: bjorn.
-rw-r--r-- | src/actorspritemanager.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 88ecd86b..2ee80d03 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -179,6 +179,9 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const const int halfTileHeight = map->getTileHeight() / 2; + Being *closest = 0; + int closestDist; + for_actors { if ((*it)->getType() == ActorSprite::FLOOR_ITEM) @@ -188,20 +191,28 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const const int halfWidth = std::max(16, being->getWidth() / 2); const int height = std::max(32, being->getHeight()); + const int halfHeight = height / 2; // Being sprites are drawn half a tile lower than they actually stand const int bottom = being->getPixelY() + halfTileHeight; - if (being->isAlive() && - being != local_player && - being->getPixelX() - halfWidth <= x && - being->getPixelX() + halfWidth >= x && - bottom - height <= y && - bottom >= y) - return being; + const int dist = std::max(std::abs(bottom - halfHeight - y), + std::abs(being->getPixelX() - x)); + + if ((being->isAlive() && + being != local_player && + being->getPixelX() - halfWidth <= x && + being->getPixelX() + halfWidth >= x && + bottom - height <= y && + bottom >= y) && + (!closest || closestDist > dist)) + { + closest = being; + closestDist = dist; + } } - return NULL; + return closest; } FloorItem *ActorSpriteManager::findItem(int id) const |