diff options
author | Bertram <bertram@cegetel.net> | 2010-03-03 20:33:40 +0100 |
---|---|---|
committer | Bertram <yohanndotferreiraatorange.fr> | 2010-04-12 23:50:22 +0200 |
commit | 27c7c5f725f5cf1e3393df9393b08fdc26057212 (patch) | |
tree | 566f9d7b043e7482331a0091f03daacd0d095db9 | |
parent | 1bc96ba79136e8e47c077039d09e8a027569bcdb (diff) | |
download | mana-27c7c5f725f5cf1e3393df9393b08fdc26057212.tar.gz mana-27c7c5f725f5cf1e3393df9393b08fdc26057212.tar.bz2 mana-27c7c5f725f5cf1e3393df9393b08fdc26057212.tar.xz mana-27c7c5f725f5cf1e3393df9393b08fdc26057212.zip |
Added the player collision rectangle and tweaked colors
-rw-r--r-- | src/being.cpp | 16 | ||||
-rw-r--r-- | src/being.h | 5 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 11 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/being.cpp b/src/being.cpp index 200f38cf..2500061a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -150,11 +150,10 @@ void Being::setDestination(int dstX, int dstY) if (!mMap->getWalk(dstX / 32, dstY / 32)) return; - // The being radius should be obtained from xml values. - Position dest = mMap->checkNodeOffsets(getWidth() / 2, getWalkMask(), + Position dest = mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(), dstX, dstY); Path thisPath = mMap->findPixelPath(mPos.x, mPos.y, dest.x, dest.y, - getWidth() / 2, getWalkMask()); + getCollisionRadius(), getWalkMask()); if (thisPath.empty()) { @@ -511,6 +510,17 @@ void Being::nextTile() mWalkTime += (int)(mWalkSpeed.x / 10); } +int Being::getCollisionRadius() const +{ + // FIXME: Get this from XML file + int radius = getWidth() / 2; + if (radius > 32 / 2) radius = 32 / 2; + // set a default value if no value returned. + if (radius < 1) radius = 32 / 3; + + return radius; +} + void Being::logic() { // Reduce the time that speech is still displayed diff --git a/src/being.h b/src/being.h index 96c25ffc..3479a9a8 100644 --- a/src/being.h +++ b/src/being.h @@ -442,6 +442,11 @@ class Being : public Sprite, public ConfigListener virtual int getHeight() const; /** + * Returns the being's pixel radius used to detect collisions. + */ + virtual int getCollisionRadius() const; + + /** * Returns the required size of a target cursor for this being. */ virtual Being::TargetCursorSize getTargetCursorSize() const diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 1c0959d7..ac9bfb2e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -277,16 +277,23 @@ void Viewport::_drawDebugPath(Graphics *graphics) else if (Net::getNetworkType() == ServerInfo::MANASERV) { const Vector &playerPos = player_node->getPosition(); + const int playerRadius = player_node->getCollisionRadius(); + // Draw player collision rectangle + graphics->setColor(gcn::Color(128, 128, 0, 120)); + graphics->fillRectangle( + gcn::Rectangle((int) playerPos.x - (int) mPixelViewX - playerRadius, + (int) playerPos.y - (int) mPixelViewY - playerRadius, + playerRadius * 2, playerRadius * 2)); debugPath = mMap->findPixelPath( (int) playerPos.x, (int) playerPos.y, mMouseX + (int) mPixelViewX, mMouseY + (int) mPixelViewY, - player_node->getWidth() / 2, 0xFF); + playerRadius, 0xFF); // We draw the path proposed by mouse - _drawPath(graphics, debugPath, gcn::Color(255, 0, 255)); + _drawPath(graphics, debugPath, gcn::Color(128, 0, 128)); // But also the one currently walked on. _drawPath(graphics, player_node->getPath(), gcn::Color(0, 0, 255)); |