Moved Weapon from Player to Character.

This commit is contained in:
Felix Ableitner 2012-10-13 18:57:12 +02:00
parent 5517db89c7
commit c1c461f8e2
4 changed files with 15 additions and 6 deletions

View file

@ -25,6 +25,7 @@ Character::Character(const Instances& instances, const String& texturePath,
mMaxHealth(config.get<int>(KEY_HEALTH)), mMaxHealth(config.get<int>(KEY_HEALTH)),
mCurrentHealth(mMaxHealth), mCurrentHealth(mMaxHealth),
mMovementSpeed(config.get<float>(KEY_SPEED)), mMovementSpeed(config.get<float>(KEY_SPEED)),
mWeapon(instances, *this, Yaml("weapon.yaml")),
mInstances(instances) { mInstances(instances) {
mCharacterInstances.push_back(this); mCharacterInstances.push_back(this);
} }
@ -93,3 +94,11 @@ float
Character::getMovementSpeed() const { Character::getMovementSpeed() const {
return mMovementSpeed; return mMovementSpeed;
} }
/**
* Fire the attached weapon.
*/
void
Character::fire() {
mWeapon.fire();
}

View file

@ -11,10 +11,12 @@
#include <vector> #include <vector>
#include "Sprite.h" #include "Sprite.h"
#include "../items/Weapon.h"
#include "../util/Instances.h" #include "../util/Instances.h"
#include "../util/String.h" #include "../util/String.h"
#include "../util/Yaml.h" #include "../util/Yaml.h"
class Weapon;
class Instances; class Instances;
class Sprite; class Sprite;
class Yaml; class Yaml;
@ -38,6 +40,7 @@ protected:
virtual void onThink(float elapsedTime); virtual void onThink(float elapsedTime);
virtual void onDeath(); virtual void onDeath();
float getMovementSpeed() const; float getMovementSpeed() const;
void fire();
// Private variables. // Private variables.
private: private:
@ -49,6 +52,7 @@ private:
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; const float mMovementSpeed;
Weapon mWeapon;
Instances mInstances; Instances mInstances;
}; };

View file

@ -21,7 +21,6 @@ const float Player::POINT_REACHED_DISTANCE = 1.0f;
Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) : Player::Player(const Instances& instances, const Vector2f& position, const Yaml& config) :
Character(instances, "player.png", PhysicalData(position, instances.world, Character(instances, "player.png", PhysicalData(position, instances.world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), config), CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
mWeapon(instances, *this, Yaml("weapon.yaml")),
mDirection(0), mDirection(0),
mPathfinder(instances.pathfinder) { mPathfinder(instances.pathfinder) {
} }
@ -41,7 +40,7 @@ Player::setCrosshairPosition(const Vector2f& position) {
*/ */
void void
Player::fire() { Player::fire() {
mWeapon.fire(); Character::fire();
} }
/** /**

View file

@ -59,11 +59,8 @@ private:
/// 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;
Weapon mWeapon; //< Weapon object used for Player::fire().
Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor). Vector2f mCrosshairPosition; //< Relative position of the point to fire at (mouse cursor).
uint8 mDirection; //< Current movement direction for direct control. uint8 mDirection; //< Current movement direction for direct control.
Pathfinder& mPathfinder; Pathfinder& mPathfinder;
std::vector<Vector2f> mPath; std::vector<Vector2f> mPath;
}; };