diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index 8d11f6e..d9c5ca8 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -13,6 +13,7 @@ #include "../sprite/Body.h" const String Character::KEY_HEALTH = "health"; +const String Character::KEY_SPEED = "speed"; std::vector Character::mCharacterInstances = std::vector(); /** @@ -23,6 +24,7 @@ Character::Character(const Instances& instances, const String& texturePath, Sprite(config, data), mMaxHealth(config.get(KEY_HEALTH)), mCurrentHealth(mMaxHealth), + mMovementSpeed(config.get(KEY_SPEED)), mInstances(instances) { mCharacterInstances.push_back(this); } @@ -83,3 +85,11 @@ Character::onThink(float elapsedTime) { void Character::onDeath() { } + +/** + * Gets the default movement speed (walking) of the character. + */ +float +Character::getMovementSpeed() const { + return mMovementSpeed; +} diff --git a/source/abstract/Character.h b/source/abstract/Character.h index fa52873..4fcba48 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -37,15 +37,18 @@ public: protected: virtual void onThink(float elapsedTime); virtual void onDeath(); + float getMovementSpeed() const; // Private variables. private: static const String KEY_HEALTH; + static const String KEY_SPEED; static std::vector mCharacterInstances; const int mMaxHealth; int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. + const float mMovementSpeed; Instances mInstances; }; diff --git a/source/sprite/Player.cpp b/source/sprite/Player.cpp index ff2ed67..7bf8309 100644 --- a/source/sprite/Player.cpp +++ b/source/sprite/Player.cpp @@ -13,7 +13,6 @@ #include "../items/Weapon.h" #include "../util/String.h" -const float Player::SPEED = 100.0f; const float Player::POINT_REACHED_DISTANCE = 1.0f; /** @@ -56,7 +55,7 @@ Player::move(const Vector2f& destination) { mPath = mPathfinder.getPath(*this, destination); // Make sure we found a path. if (mPath != std::vector()) { - setSpeed(*mPath.end() - getPosition(), SPEED); + setSpeed(*mPath.end() - getPosition(), getMovementSpeed()); } // Otherwise stop (in case this was called during movement). else { @@ -92,7 +91,7 @@ Player::setDirection(Direction direction, bool unset) { if (mDirection & (uint8) Direction::UP) { dirVec.y += - 1.0f; } - setSpeed(dirVec, SPEED); + setSpeed(dirVec, getMovementSpeed()); } /** @@ -107,7 +106,7 @@ Player::onThink(float elapsedTime) { mPath.pop_back(); if (!mPath.empty()) { // Move to next. - setSpeed(*mPath.end() - getPosition(), SPEED); + setSpeed(*mPath.end() - getPosition(), getMovementSpeed()); } else { // Reached destination. diff --git a/source/sprite/Player.h b/source/sprite/Player.h index 2cf15b8..5f38a7d 100644 --- a/source/sprite/Player.h +++ b/source/sprite/Player.h @@ -56,7 +56,6 @@ private: // Private variables. private: - static const float SPEED; /// The distance to a point where it is considered reached. static const float POINT_REACHED_DISTANCE;