From 5db687147dabe7cf0a7014d3bb8deb08345dea0e Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 18 Apr 2013 12:45:37 +0200 Subject: [PATCH] Put mouse movement back in. --- source/Game.cpp | 8 +++++++- source/abstract/Character.cpp | 10 ++++++++-- source/sprites/Player.cpp | 6 ++++++ source/sprites/Player.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 7865883..0d4aac3 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -12,6 +12,8 @@ #include "sprites/Player.h" #include "util/Yaml.h" +#include "util/Log.h" + const int Game::FPS_GOAL = 60; /** @@ -83,7 +85,8 @@ Game::input() { mouseUp(event); break; case sf::Event::MouseMoved: - mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x, event.mouseMove.y)); + mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x, + event.mouseMove.y)); break; default: break; @@ -157,6 +160,9 @@ Game::mouseDown(const sf::Event& event) { case sf::Mouse::Left: mPlayer->pullTrigger(); break; + case sf::Mouse::Right: + mPlayer->setDestination(convertCoordinates(event.mouseMove.x, + event.mouseMove.y)); default: break; } diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 7fe09bf..16c6d1f 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -104,13 +104,19 @@ Character::releaseTrigger() { } /** - * Set a destination to be walked to. Call move() for the actual movement. + * Set a destination to be walked to. Call move() to actually + * perform the movement. * - * @param destination An absolute point to move towards. + * @param destination An absolute point to move towards. Set to current + * position to stop movement. * @return True if a path was found. */ bool Character::setDestination(const sf::Vector2f& destination) { + if (destination == getPosition()) { + mPath.clear(); + return true; + } mPath = mWorld.getPath(getPosition(), destination, getRadius()); if (!mPath.empty()) setSpeed(mPath.back() - getPosition(), mMovementSpeed); diff --git a/source/sprites/Player.cpp b/source/sprites/Player.cpp index 350eb7d..e69f87a 100644 --- a/source/sprites/Player.cpp +++ b/source/sprites/Player.cpp @@ -72,6 +72,12 @@ Player::setDirection(Direction direction, bool unset) { setSpeed(dirVec, getMovementSpeed()); } +void +Player::setDestination(const sf::Vector2f& destination) { + mDirection = 0; + Character::setDestination(destination); +} + /** * Check if we arrived at destination, turn towards cursor. */ diff --git a/source/sprites/Player.h b/source/sprites/Player.h index 1eea09c..5e0ab00 100644 --- a/source/sprites/Player.h +++ b/source/sprites/Player.h @@ -36,6 +36,7 @@ public: void pullTrigger(); void releaseTrigger(); void setDirection(Direction direction, bool unset); + void setDestination(const sf::Vector2f& destination); private: void onThink(int elapsed);