From d95381372559c75b1829b43f9476c21b166f6dad Mon Sep 17 00:00:00 2001 From: Bertram Date: Fri, 26 Feb 2010 21:02:34 +0100 Subject: Finished Being::checkNodeOffsets function. --- src/being.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src/being.cpp') 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); } -- cgit v1.2.3-70-g09d2