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