Put mouse movement back in.
This commit is contained in:
parent
bbdd298ebe
commit
5db687147d
4 changed files with 22 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in a new issue