summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2010-02-27 15:26:22 +0100
committerBertram <yohanndotferreiraatorange.fr>2010-04-12 23:50:21 +0200
commit98967ec85b48fcc85d1468b7fa02b847389431fb (patch)
tree48654c088a161208848928451965563eacdcd69c /src/being.cpp
parentd95381372559c75b1829b43f9476c21b166f6dad (diff)
downloadmana-98967ec85b48fcc85d1468b7fa02b847389431fb.tar.gz
mana-98967ec85b48fcc85d1468b7fa02b847389431fb.tar.bz2
mana-98967ec85b48fcc85d1468b7fa02b847389431fb.tar.xz
mana-98967ec85b48fcc85d1468b7fa02b847389431fb.zip
One step closer to the full movement system ready.
The LocalPlayer::nextTile() function has been sanitized and the movement system has been fine tuned, but yet not optimized. (Optimizations and riddance of 32 hard-coded value will come later.) There is just one case left not handled correctly when the character walked within one tile south-east of a blocking one and then the player click north-west (through the blocking tile) on a walkable location. Quite rare but still here.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/being.cpp b/src/being.cpp
index d18fcb8f..b248ffa0 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -621,7 +621,7 @@ void Being::logic()
const float nominalLength = dir.length();
// When we've not reached our destination, move to it.
- if (nominalLength > 1.0f && !mWalkSpeed.isNull())
+ if (nominalLength > 0.0f && !mWalkSpeed.isNull())
{
// The deplacement of a point along a vector is calculated
// using the Unit Vector (รข) multiplied by the point speed.
@@ -648,22 +648,26 @@ void Being::logic()
if (mAction != WALK)
setAction(WALK);
- // Update the player sprite direction
- int direction = 0;
- const float dx = std::abs(dir.x);
- float dy = std::abs(dir.y);
+ // Update the player sprite direction.
+ // N.B.: We only change this if the distance is more than one pixel.
+ if (nominalLength > 1.0f)
+ {
+ int direction = 0;
+ const float dx = std::abs(dir.x);
+ float dy = std::abs(dir.y);
- // When not using mouse for the player, we slightly prefer
- // UP and DOWN position, especially when walking diagonally.
- if (this == player_node && !player_node->isPathSetByMouse())
- dy = dy + 2;
+ // When not using mouse for the player, we slightly prefer
+ // UP and DOWN position, especially when walking diagonally.
+ if (this == player_node && !player_node->isPathSetByMouse())
+ dy = dy + 2;
- if (dx > dy)
- direction |= (dir.x > 0) ? RIGHT : LEFT;
- else
- direction |= (dir.y > 0) ? DOWN : UP;
+ if (dx > dy)
+ direction |= (dir.x > 0) ? RIGHT : LEFT;
+ else
+ direction |= (dir.y > 0) ? DOWN : UP;
- setDirection(direction);
+ setDirection(direction);
+ }
}
else if (!mPath.empty())
{