diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2008-10-26 00:02:01 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2008-10-26 00:02:01 +0000 |
commit | 050cee64b64aba57de84383c7138c1ad0f4ded55 (patch) | |
tree | 7c080b187c9a0b1d6b1435141cfb956c379b3ca4 /src | |
parent | 796c2addfb17b57992d304667248873ee26088dc (diff) | |
download | mana-050cee64b64aba57de84383c7138c1ad0f4ded55.tar.gz mana-050cee64b64aba57de84383c7138c1ad0f4ded55.tar.bz2 mana-050cee64b64aba57de84383c7138c1ad0f4ded55.tar.xz mana-050cee64b64aba57de84383c7138c1ad0f4ded55.zip |
Pixel-accurate and fluently animated keyboard movement by Kage Jittai - albeit not flawless it is still a big improvement.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 19 | ||||
-rw-r--r-- | src/localplayer.cpp | 36 | ||||
-rw-r--r-- | src/localplayer.h | 11 |
3 files changed, 60 insertions, 6 deletions
diff --git a/src/game.cpp b/src/game.cpp index fc16e1ea..901b8dea 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -787,7 +787,24 @@ void Game::handleInput() direction |= Being::RIGHT; } - player_node->setWalkingDir(direction); + // First if player is pressing key for the direction he is already going + if (direction == player_node->getWalkingDir()) + { + player_node->setWalkingDir(direction); + } + // Else if he is pressing a key, and its different from what he has + // been pressing, stop (do not send this stop to the server) and + // start in the new direction + else if (direction && direction != player_node->getWalkingDir()) + { + player_node->stopWalking(false); + player_node->setWalkingDir(direction); + } + // Else, he is not pressing a key, stop (sending to server) + else + { + player_node->stopWalking(true); + } // Target the nearest player if 'q' is pressed if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER)) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 68648d74..9c1cd743 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -46,7 +46,7 @@ #include "utils/tostring.h" #include "utils/gettext.h" -const short walkingKeyboardDelay = 100; +const short walkingKeyboardDelay = 500; LocalPlayer *player_node = NULL; @@ -242,6 +242,7 @@ void LocalPlayer::walk(unsigned char dir) return; const Vector &pos = getPosition(); + int dScaler; // Distance to walk if (mAction == WALK && !mPath.empty()) { @@ -273,11 +274,22 @@ void LocalPlayer::walk(unsigned char dir) (pos.y + dy) / 32, getWalkMask())) dx = 16 - (int) pos.x % 32; - // Walk to where the player can actually go - if ((dx || dy) && mMap->getWalk(((int) pos.x + dx) / 32, - ((int) pos.y + dy) / 32, getWalkMask())) + // Checks our path up to 5 tiles, if a blocking tile is found + // We go to the last good tile, and break out of the loop + for (dScaler = 1; dScaler <= 5; dScaler++) { - setDestination((int) pos.x + dx, (int) pos.y + dy); + if ( (dx || dy) && + !mMap->getWalk( ((int) pos.x + (dx * dScaler)) / 32, + ((int) pos.y + (dy * dScaler)) / 32, getWalkMask()) ) + { + dScaler--; + break; + } + } + + if (dScaler >= 0) + { + setDestination((int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler)); } else if (dir) { @@ -336,6 +348,20 @@ void LocalPlayer::setWalkingDir(int dir) } } +void LocalPlayer::stopWalking(bool sendToServer) +{ + if(mAction == WALK && mWalkingDir){ + mWalkingDir = 0; + mLocalWalkTime = 0; + Being::setDestination(getPosition().x,getPosition().y); + if (sendToServer) + Net::GameServer::Player::walk(getPosition().x, getPosition().y); + setAction(STAND); + } + + clearPath(); +} + void LocalPlayer::toggleSit() { if (mLastAction != -1) diff --git a/src/localplayer.h b/src/localplayer.h index 7d6f3862..7a5158cc 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -252,6 +252,17 @@ class LocalPlayer : public Player void setWalkingDir(int dir); /** + * Gets the walking direction + */ + int getWalkingDir() const + { return mWalkingDir; } + + /** + * Stops the player dead in his tracks + */ + void stopWalking(bool sendToServer = true); + + /** * Uses a character point to raise an attribute */ void raiseAttribute(size_t attr); |