diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-18 23:01:52 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-19 23:22:40 +0100 |
commit | 7272d727271b226948ff56f486a3f322fe1762bd (patch) | |
tree | 78fc7ffdf814ac01eba8766650b24f7d8892ecc9 /src/actorspritemanager.cpp | |
parent | 4159ba015c5f2035d188367d85d85052a7673cdc (diff) | |
download | mana-7272d727271b226948ff56f486a3f322fe1762bd.tar.gz mana-7272d727271b226948ff56f486a3f322fe1762bd.tar.bz2 mana-7272d727271b226948ff56f486a3f322fe1762bd.tar.xz mana-7272d727271b226948ff56f486a3f322fe1762bd.zip |
Fixed the click area for NPCs and other players
By taking into account that the sprite is drawn half a tile lower than
the position of the being (that is messy on its own, but hard to fix
while supporting both pixel and tile based movement).
It also makes sure that the click area is at least 32x32 pixels, no
matter how small the being. This fixes the lack of a clickable area
for NPCs without a sprite (like some chests or signs) and makes
small monsters like maggots easier to hit.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/actorspritemanager.cpp')
-rw-r--r-- | src/actorspritemanager.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 82e14de0..2928aa45 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -173,6 +173,12 @@ Being *ActorSpriteManager::findBeing(int x, int y, ActorSprite::Type type) const Being *ActorSpriteManager::findBeingByPixel(int x, int y) const { + Map *map = Game::instance() ? Game::instance()->getCurrentMap() : 0; + if (!map) + return 0; + + const int halfTileHeight = map->getTileHeight() / 2; + for_actors { if ((*it)->getType() == ActorSprite::FLOOR_ITEM) @@ -180,15 +186,18 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const Being *being = static_cast<Being*>(*it); - int xtol = being->getWidth() / 2; - int uptol = being->getHeight(); + const int halfWidth = std::max(16, being->getWidth() / 2); + const int height = std::max(32, being->getHeight()); + + // 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() - xtol <= x) && - (being->getPixelX() + xtol >= x) && - (being->getPixelY() - uptol <= y) && - (being->getPixelY() >= y)) + if (being->isAlive() && + being != local_player && + being->getPixelX() - halfWidth <= x && + being->getPixelX() + halfWidth >= x && + bottom - height <= y && + bottom >= y) return being; } |