From 3ca85b152531b9dd9cffa18d9b64d7c7ae615adf Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 25 Jan 2009 19:45:18 +0100 Subject: Fixed offset of right-click hitboxes and made NPCs without sprites clickable. --- src/being.cpp | 4 ++-- src/being.h | 4 ++++ src/beingmanager.cpp | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index d32ffa59..442c08ef 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -603,7 +603,7 @@ int Being::getWidth() const return mSprites[BASE_SPRITE]->getWidth(); } else { - return 0; + return Being::DEFAULT_WIDTH; } } @@ -614,7 +614,7 @@ int Being::getHeight() const return mSprites[BASE_SPRITE]->getHeight(); } else { - return 0; + return Being::DEFAULT_HEIGHT; } } diff --git a/src/being.h b/src/being.h index aeb03564..0591777e 100644 --- a/src/being.h +++ b/src/being.h @@ -411,6 +411,10 @@ class Being : public Sprite std::list mChildParticleEffects; private: + + static const int Being::DEFAULT_WIDTH = 32; + static const int Being::DEFAULT_HEIGHT = 32; + // Speech Bubble components SpeechBubble *mSpeechBubble; diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 6d9267d2..7f3d8845 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -123,12 +123,13 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) for (; itr != itr_end; ++itr) { Being *being = (*itr); - if ((being->mAction != Being::DEAD) && - (being != player_node) && - (being->getPixelX() <= x) && - (being->getPixelX() + being->getWidth() >= x) && - (being->getPixelY() <= y) && - (being->getPixelY() + being->getHeight() >= y)) + int xtol = being->getWidth() / 2; + int uptol = being->getHeight(); + if ((being != player_node) && + (being->getPixelX() - xtol <= x) && + (being->getPixelX() + xtol >= x) && + (being->getPixelY() - uptol <= y) && + (being->getPixelY() >= y)) { return being; } @@ -190,7 +191,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, //in map coords, while down below its in pixels // //I believe there is a deeper problem under this, but - //for a temp solution we'll convert to coords to pixels + //for a temp solution we'll convert to coords to pixels x = x * 32; y = y * 32; maxdist = maxdist * 32; @@ -210,8 +211,8 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, closestBeing = being; } } - - return (maxdist >= dist) ? closestBeing : NULL; + + return (maxdist >= dist) ? closestBeing : NULL; } Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, -- cgit v1.2.3-70-g09d2