Allow setting weapon damage via yaml config.
This commit is contained in:
parent
76b074220d
commit
28681c7eb3
3 changed files with 17 additions and 16 deletions
|
@ -14,26 +14,24 @@
|
|||
#include "../util/Collection.h"
|
||||
#include "../effects/Bullet.h"
|
||||
#include "../util/Loader.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
#include "../util/ResourceManager.h"
|
||||
|
||||
const String Weapon::KEY_DAMAGE = "damage";
|
||||
|
||||
const int Weapon::BULLET_DAMAGE = 10;
|
||||
|
||||
Weapon::Weapon(const Instances& instances, Physical& holder, const Vector2i& holderSize) :
|
||||
Weapon::Weapon(const Instances& instances, Physical& holder, const Yaml& config) :
|
||||
Emitter(instances.collection),
|
||||
mHolder(holder),
|
||||
mBulletTexture(ResourceManager::i()
|
||||
.acquire(Loader::i().fromFile<sf::Texture>("bullet.png"))),
|
||||
mWorld(instances.world),
|
||||
mOffset(0, std::max(holderSize.x, holderSize.y) / 2 +
|
||||
mOffset(0, std::max(mHolder.getSize().x, mHolder.getSize().y) / 2 +
|
||||
b2_linearSlop +
|
||||
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2) {
|
||||
}
|
||||
|
||||
Weapon::~Weapon() {
|
||||
std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2),
|
||||
mDamage(config.get<int>(KEY_DAMAGE)) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call on any button press/refire.
|
||||
* Pull the trigger.
|
||||
*/
|
||||
void
|
||||
Weapon::fire() {
|
||||
|
@ -47,5 +45,5 @@ Weapon::createParticle() {
|
|||
Vector2f offset(- mOffset);
|
||||
thor::rotate(offset, mHolder.getAngle());
|
||||
return std::shared_ptr<Particle>(new Bullet(mHolder.getPosition() + offset,
|
||||
mWorld, mBulletTexture, mHolder, mHolder.getAngle(), BULLET_DAMAGE));
|
||||
mWorld, mBulletTexture, mHolder, mHolder.getAngle(), mDamage));
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../Instances.h"
|
||||
#include "../abstract/Physical.h"
|
||||
#include "../particle/Emitter.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
class Emitter;
|
||||
class Instances;
|
||||
|
@ -26,8 +27,7 @@ class Physical;
|
|||
class Weapon : public Emitter {
|
||||
// Public functions.
|
||||
public:
|
||||
Weapon(const Instances& instances, Physical& holder, const Vector2i& holderSize);
|
||||
~Weapon();
|
||||
Weapon(const Instances& instances, Physical& holder, const Yaml& config);
|
||||
|
||||
void fire();
|
||||
|
||||
|
@ -37,12 +37,14 @@ protected:
|
|||
|
||||
// Private variables.
|
||||
private:
|
||||
static const int BULLET_DAMAGE;
|
||||
static const String KEY_DAMAGE;
|
||||
|
||||
Physical& mHolder;
|
||||
std::shared_ptr<sf::Texture> mBulletTexture;
|
||||
b2World& mWorld;
|
||||
const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
|
||||
const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center).
|
||||
const int mDamage;
|
||||
};
|
||||
|
||||
#endif /* DG_WEAPON_H_ */
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "../util/Vector.h"
|
||||
#include "../items/Weapon.h"
|
||||
#include "../util/String.h"
|
||||
#include "../util/Yaml.h"
|
||||
|
||||
const float Player::SPEED = 100.0f;
|
||||
const Vector2i Player::SIZE = Vector2i(50, 50);
|
||||
|
@ -23,7 +24,7 @@ const float Player::POINT_REACHED_DISTANCE = 1.0f;
|
|||
Player::Player(const Instances& instances, const Vector2f& position) :
|
||||
Character(instances, "player.png", PhysicalData(position, SIZE, instances.world,
|
||||
CATEGORY_ACTOR, MASK_ALL, true, false, true), 100),
|
||||
mWeapon(instances, *this, SIZE),
|
||||
mWeapon(instances, *this, Yaml("weapon.yaml")),
|
||||
mDirection(0),
|
||||
mPathfinder(instances.pathfinder) {
|
||||
}
|
||||
|
|
Reference in a new issue