diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 16c6d1f..863e103 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -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. * * @param elapsed Amount of time to simulate. @@ -68,6 +68,7 @@ Character::onDamage(int damage) { void Character::onThink(int elapsed) { mWeapon->onThink(elapsed); + move(); } /** @@ -118,16 +119,16 @@ Character::setDestination(const sf::Vector2f& destination) { return true; } mPath = mWorld.getPath(getPosition(), destination, getRadius()); - if (!mPath.empty()) + if (!mPath.empty()) setSpeed(mPath.back() - getPosition(), mMovementSpeed); - else + else LOG_W("No path found to destination."); return !mPath.empty(); } /** * 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 Character::move() { diff --git a/source/abstract/Character.h b/source/abstract/Character.h index 91f14ed..330bfba 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -33,11 +33,13 @@ protected: void pullTrigger(); void releaseTrigger(); bool setDestination(const sf::Vector2f& destination); - void move(); bool isMoving() const; bool isVisible(const sf::Vector2f& target) const; std::vector > getCharacters() const; +private: + void move(); + private: static const std::string KEY_HEALTH; static const int DEFAULT_HEALTH; diff --git a/source/sprites/Enemy.cpp b/source/sprites/Enemy.cpp index 4852e16..8363c22 100644 --- a/source/sprites/Enemy.cpp +++ b/source/sprites/Enemy.cpp @@ -34,9 +34,7 @@ Enemy::onThink(int elapsed) { setDirection(target->getPosition() - getPosition()); pullTrigger(); } - else if (isMoving()) - move(); - else + else if (!isMoving()) setDestination(target->getPosition()); } else