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)),
mCurrentHealth(mMaxHealth),
mMovementSpeed(config.get<float>(KEY_SPEED)),
mWeapon(instances, *this, Yaml("weapon.yaml")),
mInstances(instances) {
mCharacterInstances.push_back(this);
}
@ -93,3 +94,11 @@ float
Character::getMovementSpeed() const {
return mMovementSpeed;
}
/**
* Fire the attached weapon.
*/
void
Character::fire() {
mWeapon.fire();
}

View file

@ -11,10 +11,12 @@
#include <vector>
#include "Sprite.h"
#include "../items/Weapon.h"
#include "../util/Instances.h"
#include "../util/String.h"
#include "../util/Yaml.h"
class Weapon;
class Instances;
class Sprite;
class Yaml;
@ -38,6 +40,7 @@ protected:
virtual void onThink(float elapsedTime);
virtual void onDeath();
float getMovementSpeed() const;
void fire();
// Private variables.
private:
@ -49,6 +52,7 @@ private:
const int mMaxHealth;
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth.
const float mMovementSpeed;
Weapon mWeapon;
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) :
Character(instances, "player.png", PhysicalData(position, instances.world,
CATEGORY_ACTOR, MASK_ALL, true, false, true), config),
mWeapon(instances, *this, Yaml("weapon.yaml")),
mDirection(0),
mPathfinder(instances.pathfinder) {
}
@ -41,7 +40,7 @@ Player::setCrosshairPosition(const Vector2f& position) {
*/
void
Player::fire() {
mWeapon.fire();
Character::fire();
}
/**

View file

@ -59,11 +59,8 @@ private:
/// The distance to a point where it is considered reached.
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).
uint8 mDirection; //< Current movement direction for direct control.
Pathfinder& mPathfinder;
std::vector<Vector2f> mPath;
};