summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 08f5a491..1018b8e1 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -422,20 +422,17 @@ Being::nextStep()
PATH_NODE node = mPath.front();
mPath.pop_front();
- int dir = 0;
- if (node.x > mX)
- dir |= RIGHT;
- else if (node.x < mX)
- dir |= LEFT;
- if (node.y > mY)
- dir |= DOWN;
- else if (node.y < mY)
- dir |= UP;
+ mStepX = node.x - mX;
+ mStepY = node.y - mY;
+
+ int dir = 0, dx = std::abs(mStepX), dy = std::abs(mStepY);
+ if (dx * 2 > dy)
+ dir |= mStepX > 0 ? RIGHT : LEFT;
+ if (dy * 2 > dx)
+ dir |= mStepY > 0 ? DOWN : UP;
setDirection(dir);
- mStepX = node.x - mX;
- mStepY = node.y - mY;
mX = node.x;
mY = node.y;
setAction(WALK);