aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/entities.hpp2
-rw-r--r--main.cpp4
-rw-r--r--src/entities.cpp4
-rw-r--r--src/mob.cpp1
-rw-r--r--src/world.cpp4
5 files changed, 8 insertions, 7 deletions
diff --git a/include/entities.hpp b/include/entities.hpp
index 82f80c7..ca4ef2b 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -284,7 +284,7 @@ public:
bool isHit(void) const;
// returns true if this entity is near the one provided
- bool isNear(Entity e);
+ bool isNear(const Entity *e);
// returns true if the coordinate is within the entity
bool isInside(vec2 coord) const;
diff --git a/main.cpp b/main.cpp
index 2f094dc..d61acf1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -536,7 +536,7 @@ void logic(){
}
}
- if(e->isInside(ui::mouse) && player->isNear(*e)) {
+ if(e->isInside(ui::mouse) && player->isNear(e)) {
e->near = true;
if (e->type == OBJECTT)
ObjectSelected = true;
@@ -554,7 +554,7 @@ void logic(){
e->near = false;
}
} else if (e->type == MOBT) {
- e->near = player->isNear(*e);
+ e->near = player->isNear(e);
e->wander();
}
}
diff --git a/src/entities.cpp b/src/entities.cpp
index 8299e2c..b417f11 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -329,8 +329,8 @@ void Object::reloadTexture(void)
height = getItemHeight(iname);
}
-bool Entity::isNear(Entity e) {
- return pow(e.loc.x - loc.x, 2) + pow(e.loc.y - loc.y, 2) <= pow(HLINES(40), 2);
+bool Entity::isNear(const Entity *e) {
+ return pow(e->loc.x - loc.x, 2) + pow(e->loc.y - loc.y, 2) <= pow(HLINES(40), 2);
}
void NPC::drawThingy(void) const
diff --git a/src/mob.cpp b/src/mob.cpp
index 1f998f7..d6df3fd 100644
--- a/src/mob.cpp
+++ b/src/mob.cpp
@@ -11,6 +11,7 @@ Mob::Mob(void)
inv = nullptr;
rider = nullptr;
canMove = true;
+ loc = 0;
}
Page::Page(void) : Mob()
diff --git a/src/world.cpp b/src/world.cpp
index efafa55..e6c5f0d 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -1030,7 +1030,7 @@ getNearInteractable(Entity &e)
{
auto n = std::find_if(std::begin(entity), std::end(entity), [&](Entity *&a) {
return ((a->type == MOBT) || (a->type == NPCT) || a->type == MERCHT) &&
- e.isNear(*a) && (e.left ? (a->loc.x < e.loc.x) : (a->loc.x > e.loc.x));
+ e.isNear(a) && (e.left ? (a->loc.x < e.loc.x) : (a->loc.x > e.loc.x));
});
return n == std::end(entity) ? nullptr : *n;
@@ -1040,7 +1040,7 @@ Mob *World::
getNearMob(Entity &e)
{
auto n = std::find_if(std::begin(mob), std::end(mob), [&](Mob *&a) {
- return e.isNear(*a) && (e.left ? (a->loc.x < e.loc.x + e.width / 2) : (a->loc.x > e.loc.x + e.width / 2));
+ return e.isNear(a) && (e.left ? (a->loc.x < e.loc.x + e.width / 2) : (a->loc.x > e.loc.x + e.width / 2));
});
return n == std::end(mob) ? nullptr : *n;