From 4720134d58cd5fe0846ed911b360ed75641cb874 Mon Sep 17 00:00:00 2001 From: Bertram Date: Thu, 22 Oct 2009 01:18:41 +0200 Subject: Fix flipping player's direction when using keyboard to walk diagonally. --- src/being.cpp | 8 +++++++- src/localplayer.cpp | 4 ++-- src/localplayer.h | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index d133225f..69e01dba 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -575,7 +575,13 @@ void Being::logic() // Update the player sprite direction int direction = 0; const float dx = std::abs(dir.x); - const float dy = std::abs(dir.y); + float dy = std::abs(dir.y); + + // When not using mouse for the player, we slightly prefer + // UP and DOWN position, especially when walking diagonally. + if (this == player_node && !player_node->isPathSetByMouse()) + dy = dy + 2; + if (dx > dy) direction |= (dir.x > 0) ? RIGHT : LEFT; else diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 78988aa1..42da1bf9 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -302,7 +302,7 @@ void LocalPlayer::nextStep(unsigned char dir = 0) const Vector &pos = getPosition(); - // Compute where the next step will set. + // Compute where the next step will be set. int dx = 0, dy = 0; if (dir & UP) @@ -342,7 +342,7 @@ void LocalPlayer::nextStep(unsigned char dir = 0) } } - if (dScaler >= 0) + if (dScaler > 0) { //effectManager->trigger(15, (int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler)); setDestination((int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler)); diff --git a/src/localplayer.h b/src/localplayer.h index 9229c583..57e1bb35 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -367,10 +367,14 @@ class LocalPlayer : public Player std::pair getExperience(int skill); - /** Tells the path has been set by mouse */ + /** Tells that the path has been set by mouse. */ void pathSetByMouse() { mPathSetByMouse = true; } + /** Tells if the path has been set by mouse. */ + bool isPathSetByMouse() const + { return mPathSetByMouse; } + bool mUpdateName; /** Whether or not the name settings have changed */ bool mMapInitialized; /** Whether or not the map is available yet */ -- cgit v1.2.3-60-g2f50