summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--src/game.cpp19
-rw-r--r--src/localplayer.cpp36
-rw-r--r--src/localplayer.h11
4 files changed, 66 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index e91af135..8225ff6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-10-25 Chuck Miller <shadowmil@gmail.com>
+
+ * src/localplayer.h,src/localplayer.cpp,src/game.cpp: Played around
+ with movement, its still not where it should be, but its quite a bit
+ better.
+
2008-10-24 Chuck Miller <shadowmil@gmail.com>
* src/resources/iteminfo.h,src/resources/itemdb.cpp: Added attack
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);