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 "sprites/Player.h"
|
||||||
#include "util/Yaml.h"
|
#include "util/Yaml.h"
|
||||||
|
|
||||||
|
#include "util/Log.h"
|
||||||
|
|
||||||
const int Game::FPS_GOAL = 60;
|
const int Game::FPS_GOAL = 60;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +85,8 @@ Game::input() {
|
||||||
mouseUp(event);
|
mouseUp(event);
|
||||||
break;
|
break;
|
||||||
case sf::Event::MouseMoved:
|
case sf::Event::MouseMoved:
|
||||||
mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x, event.mouseMove.y));
|
mPlayer->setCrosshairPosition(convertCoordinates(event.mouseMove.x,
|
||||||
|
event.mouseMove.y));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -157,6 +160,9 @@ Game::mouseDown(const sf::Event& event) {
|
||||||
case sf::Mouse::Left:
|
case sf::Mouse::Left:
|
||||||
mPlayer->pullTrigger();
|
mPlayer->pullTrigger();
|
||||||
break;
|
break;
|
||||||
|
case sf::Mouse::Right:
|
||||||
|
mPlayer->setDestination(convertCoordinates(event.mouseMove.x,
|
||||||
|
event.mouseMove.y));
|
||||||
default:
|
default:
|
||||||
break;
|
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.
|
* @return True if a path was found.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
Character::setDestination(const sf::Vector2f& destination) {
|
Character::setDestination(const sf::Vector2f& destination) {
|
||||||
|
if (destination == getPosition()) {
|
||||||
|
mPath.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
mPath = mWorld.getPath(getPosition(), destination, getRadius());
|
mPath = mWorld.getPath(getPosition(), destination, getRadius());
|
||||||
if (!mPath.empty())
|
if (!mPath.empty())
|
||||||
setSpeed(mPath.back() - getPosition(), mMovementSpeed);
|
setSpeed(mPath.back() - getPosition(), mMovementSpeed);
|
||||||
|
|
|
@ -72,6 +72,12 @@ Player::setDirection(Direction direction, bool unset) {
|
||||||
setSpeed(dirVec, getMovementSpeed());
|
setSpeed(dirVec, getMovementSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Player::setDestination(const sf::Vector2f& destination) {
|
||||||
|
mDirection = 0;
|
||||||
|
Character::setDestination(destination);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if we arrived at destination, turn towards cursor.
|
* Check if we arrived at destination, turn towards cursor.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
void pullTrigger();
|
void pullTrigger();
|
||||||
void releaseTrigger();
|
void releaseTrigger();
|
||||||
void setDirection(Direction direction, bool unset);
|
void setDirection(Direction direction, bool unset);
|
||||||
|
void setDestination(const sf::Vector2f& destination);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onThink(int elapsed);
|
void onThink(int elapsed);
|
||||||
|
|
Reference in a new issue