summaryrefslogtreecommitdiff
path: root/src/beingmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r--src/beingmanager.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 551820da..3c8edf86 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -31,6 +31,8 @@
#include "utils/dtor.h"
+#include <cassert>
+
class FindBeingFunctor
{
public:
@@ -128,12 +130,16 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y)
for (; itr != itr_end; ++itr)
{
Being *being = (*itr);
+
+ int xtol = being->getWidth();
+ int uptol = being->getHeight() / 2;
+
if ((being->mAction != Being::DEAD) &&
(being != player_node) &&
(being->getPixelX() <= x) &&
- (being->getPixelX() + being->getWidth() >= x) &&
- (being->getPixelY() <= y) &&
- (being->getPixelY() + being->getHeight() >= y))
+ (being->getPixelX() + xtol >= x) &&
+ (being->getPixelY() - uptol <= y) &&
+ (being->getPixelY() + uptol >= y))
{
return being;
}
@@ -155,8 +161,6 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type)
return NULL;
}
-
-
Beings& BeingManager::getAll()
{
return mBeings;
@@ -204,9 +208,12 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist,
Being *closestBeing = NULL;
int dist = 0;
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ BeingIterator itr = mBeings.begin();
+ BeingIterator itr_end = mBeings.end();
+
+ for (; itr != itr_end; ++itr)
{
- Being *being = (*i);
+ Being *being = (*itr);
int d = abs(being->mX - x) + abs(being->mY - y);
if ((being->getType() == type || type == Being::UNKNOWN)