From b1845e9e081df1fc77d9bcbed3ab95792d6ba682 Mon Sep 17 00:00:00 2001 From: Bertram Date: Tue, 23 Feb 2010 23:09:06 +0100 Subject: Added diagonal movement corrections and corrected some comments. --- src/being.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index ce6c9e1b..b5d0cedb 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -139,13 +139,13 @@ Position Being::checkNodeOffsets(Position position) // Compute the being radius: // FIXME: the beings' radius should be obtained from xml values - // and stored into the Being ojects. + // and stored into the Being objects. int radius = getWidth() / 2; - // FIXME: Hande beings with more than 1/2 tile radius by not letting them + // FIXME: Handle beings with more than 1/2 tile radius by not letting them // go or spawn in too narrow places. The server will have to be aware // of being's radius value (in tiles) to handle this gracefully. if (radius > 32 / 2) radius = 32 / 2; - // set a default value if no value returned. + // Set a default value if no value returned. if (radius < 1) radius = 32 / 3; // Fix coordinates so that the player does not seem to dig into walls. @@ -158,13 +158,32 @@ Position Being::checkNodeOffsets(Position position) 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; + // 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; + } return Position(tx * 32 + fx, ty * 32 + fy); } -- cgit v1.2.3-60-g2f50