summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 15:06:46 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-12-30 15:06:46 +0000
commit9266a94488be76e8cb9700a1426832dfc914320c (patch)
tree5cdf83c6af0cd712c426581f6bb67cb932a5aab1
parent8b72679ea1d934f24e7864a843dd92a99e2cdb5b (diff)
downloadmana-client-9266a94488be76e8cb9700a1426832dfc914320c.tar.gz
mana-client-9266a94488be76e8cb9700a1426832dfc914320c.tar.bz2
mana-client-9266a94488be76e8cb9700a1426832dfc914320c.tar.xz
mana-client-9266a94488be76e8cb9700a1426832dfc914320c.zip
Improved precise positionning of character with mouse cursor.
-rw-r--r--ChangeLog6
-rw-r--r--src/being.cpp19
-rw-r--r--src/localplayer.cpp6
3 files changed, 15 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 38aaf3b6..102f5ffa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,11 @@
2006-12-30 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/being.h, src/being.cpp: Improved movement smoothness by avoiding
- useless changes of sprite direction.
+ useless changes of sprite direction. Reduced field of direction
+ components from 180° to 120° when computing being direction.
* src/localplayer.cpp: Changed attack message to send the direction
- the player is visually facing.
+ the player is visually facing. Removed check on beings when setting an
+ absolute destination.
2006-12-29 Guillaume Melquiond <guillaume.melquiond@gmail.com>
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);
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 962a1ae4..ba7b6117 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -218,9 +218,9 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y)
{
// Fix coordinates so that the player does not seem to dig into walls.
int tx = x / 32, ty = y / 32, fx = x % 32, fy = y % 32;
- if (fx != 16 && !mMap->getWalk(tx + fx / 16 * 2 - 1, ty)) fx = 16;
- if (fy != 16 && !mMap->getWalk(tx, ty + fy / 16 * 2 - 1)) fy = 16;
- if (fx != 16 && fy != 16 && !mMap->getWalk(tx + fx / 16 * 2 - 1, ty + fy / 16 * 2 - 1)) fx = 16;
+ if (fx != 16 && mMap->tileCollides(tx + fx / 16 * 2 - 1, ty)) fx = 16;
+ if (fy != 16 && mMap->tileCollides(tx, ty + fy / 16 * 2 - 1)) fy = 16;
+ if (fx != 16 && fy != 16 && mMap->tileCollides(tx + fx / 16 * 2 - 1, ty + fy / 16 * 2 - 1)) fx = 16;
x = tx * 32 + fx;
y = ty * 32 + fy;