Fixed player path finding, made Character::move() private.

This commit is contained in:
Felix Ableitner 2013-04-25 21:57:37 +02:00
parent 0b792295f7
commit d585a82ada
3 changed files with 9 additions and 8 deletions

View file

@ -60,7 +60,7 @@ Character::onDamage(int damage) {
} }
/** /**
* Implement this function for any (regular) AI computations. * Implement this function for any (periodical) AI computations.
* If overwritten, this function should always be called from the overwriting function. * If overwritten, this function should always be called from the overwriting function.
* *
* @param elapsed Amount of time to simulate. * @param elapsed Amount of time to simulate.
@ -68,6 +68,7 @@ Character::onDamage(int damage) {
void void
Character::onThink(int elapsed) { Character::onThink(int elapsed) {
mWeapon->onThink(elapsed); mWeapon->onThink(elapsed);
move();
} }
/** /**
@ -118,16 +119,16 @@ Character::setDestination(const sf::Vector2f& destination) {
return true; 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);
else else
LOG_W("No path found to destination."); LOG_W("No path found to destination.");
return !mPath.empty(); return !mPath.empty();
} }
/** /**
* Move towards a destination. Call setDestination() for setting the destination. * Move towards a destination. Call setDestination() for setting the destination.
* This should be called from think() if path finding is to be used. * This is automatically called from onThink().
*/ */
void void
Character::move() { Character::move() {

View file

@ -33,11 +33,13 @@ protected:
void pullTrigger(); void pullTrigger();
void releaseTrigger(); void releaseTrigger();
bool setDestination(const sf::Vector2f& destination); bool setDestination(const sf::Vector2f& destination);
void move();
bool isMoving() const; bool isMoving() const;
bool isVisible(const sf::Vector2f& target) const; bool isVisible(const sf::Vector2f& target) const;
std::vector<std::shared_ptr<Character> > getCharacters() const; std::vector<std::shared_ptr<Character> > getCharacters() const;
private:
void move();
private: private:
static const std::string KEY_HEALTH; static const std::string KEY_HEALTH;
static const int DEFAULT_HEALTH; static const int DEFAULT_HEALTH;

View file

@ -34,9 +34,7 @@ Enemy::onThink(int elapsed) {
setDirection(target->getPosition() - getPosition()); setDirection(target->getPosition() - getPosition());
pullTrigger(); pullTrigger();
} }
else if (isMoving()) else if (!isMoving())
move();
else
setDestination(target->getPosition()); setDestination(target->getPosition());
} }
else else