diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 15:06:46 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-30 15:06:46 +0000 |
commit | 9266a94488be76e8cb9700a1426832dfc914320c (patch) | |
tree | 5cdf83c6af0cd712c426581f6bb67cb932a5aab1 /src/being.cpp | |
parent | 8b72679ea1d934f24e7864a843dd92a99e2cdb5b (diff) | |
download | mana-9266a94488be76e8cb9700a1426832dfc914320c.tar.gz mana-9266a94488be76e8cb9700a1426832dfc914320c.tar.bz2 mana-9266a94488be76e8cb9700a1426832dfc914320c.tar.xz mana-9266a94488be76e8cb9700a1426832dfc914320c.zip |
Improved precise positionning of character with mouse cursor.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 19 |
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); |