summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2010-02-26 21:02:34 +0100
committerBertram <yohanndotferreiraatorange.fr>2010-04-12 23:50:21 +0200
commitd95381372559c75b1829b43f9476c21b166f6dad (patch)
treefa3bb92f65f5c3452c1bda5a6dcc9337d910d444 /src
parent612c842f32fec68ece4244ac672a1b889cf2eb18 (diff)
downloadmana-client-d95381372559c75b1829b43f9476c21b166f6dad.tar.gz
mana-client-d95381372559c75b1829b43f9476c21b166f6dad.tar.bz2
mana-client-d95381372559c75b1829b43f9476c21b166f6dad.tar.xz
mana-client-d95381372559c75b1829b43f9476c21b166f6dad.zip
Finished Being::checkNodeOffsets function.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 1d9047d1..d18fcb8f 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -148,6 +148,34 @@ Position Being::checkNodeOffsets(const Position &position) const
// set a default value if no value returned.
if (radius < 1) radius = 32 / 3;
+ // We check diagonal first as they are more restrictive.
+ // Top-left border check
+ if (!mMap->getWalk(tx - 1, ty - 1, getWalkMask())
+ && fy < radius && fx < radius)
+ {
+ fx = fy = radius;
+ }
+ // Top-right border check
+ if (!mMap->getWalk(tx + 1, ty - 1, getWalkMask())
+ && (fy < radius) && fx > (32 - radius))
+ {
+ fx = 32 -radius;
+ fy = radius;
+ }
+ // Bottom-left border check
+ if (!mMap->getWalk(tx - 1, ty + 1, getWalkMask())
+ && fy > (32 - radius) && fx < radius)
+ {
+ fx = radius;
+ fy = 32 - radius;
+ }
+ // Bottom-right border check
+ if (!mMap->getWalk(tx + 1, ty + 1, getWalkMask())
+ && fy > (32 - radius) && fx > (32 - radius))
+ {
+ fx = fy = 32 -radius;
+ }
+
// Fix coordinates so that the player does not seem to dig into walls.
if (fx > (32 - radius) && !mMap->getWalk(tx + 1, ty, getWalkMask()))
fx = 32 - radius;
@@ -158,14 +186,6 @@ Position Being::checkNodeOffsets(const Position &position) const
else if (fy < radius && !mMap->getWalk(tx, ty - 1, getWalkMask()))
fy = radius;
- // FIXME: Check also diagonal positions.
-
- // Test also the current character's position, to avoid the corner case
- // where a player can approach an obstacle by walking from slightly
- // under, diagonally. First part to the walk on water bug.
- //if (offsetY < 16 && !mMap->getWalk(posX, posY - 1, getWalkMask()))
- //fy = 16;
-
return Position(tx * 32 + fx, ty * 32 + fy);
}