Moved movent speed to Character (loaded from yaml).
This commit is contained in:
parent
11da25ce69
commit
5517db89c7
4 changed files with 16 additions and 5 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "../sprite/Body.h"
|
||||
|
||||
const String Character::KEY_HEALTH = "health";
|
||||
const String Character::KEY_SPEED = "speed";
|
||||
std::vector<Character*> Character::mCharacterInstances = std::vector<Character*>();
|
||||
|
||||
/**
|
||||
|
@ -23,6 +24,7 @@ Character::Character(const Instances& instances, const String& texturePath,
|
|||
Sprite(config, data),
|
||||
mMaxHealth(config.get<int>(KEY_HEALTH)),
|
||||
mCurrentHealth(mMaxHealth),
|
||||
mMovementSpeed(config.get<float>(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;
|
||||
}
|
||||
|
|
|
@ -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<Character*> mCharacterInstances;
|
||||
|
||||
const int mMaxHealth;
|
||||
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
|
||||
const float mMovementSpeed;
|
||||
Instances mInstances;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<Vector2f>()) {
|
||||
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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Reference in a new issue