diff --git a/source/effects/Bullet.cpp b/source/effects/Bullet.cpp index 5a24487..6236f06 100755 --- a/source/effects/Bullet.cpp +++ b/source/effects/Bullet.cpp @@ -8,10 +8,12 @@ #include "Bullet.h" #include "../abstract/Character.h" +#include "../util/Loader.h" +#include "../util/ResourceManager.h" const Vector2i Bullet::SIZE = Vector2i(20, 20); - -const float Bullet::SPEED = 500.0f; +const String Bullet::KEY_DAMAGE = "damage"; +const String Bullet::KEY_SPEED = "speed"; /** * Places a bullet in the world. @@ -20,13 +22,15 @@ const float Bullet::SPEED = 500.0f; * @param world Box2d world. * @param texture Texture to display for bullet. */ -Bullet::Bullet(const Vector2f& position, b2World& world, - const std::shared_ptr& texture, Physical& shooter, float direction, int damage) : - Particle(texture, PhysicalData(position, SIZE, world, CATEGORY_PARTICLE, - CATEGORY_PARTICLE, true, true, true)), +Bullet::Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction, + const Yaml& config) : + Particle(ResourceManager::i().acquire(Loader::i().fromFile("bullet.png")), + PhysicalData(position, SIZE, world, CATEGORY_PARTICLE, CATEGORY_PARTICLE, + true, true, true)), mShooter(shooter), - mDamage(damage) { - setSpeed(angle(direction), SPEED); + mDamage(config.get(KEY_DAMAGE)), + mSpeed(config.get(KEY_SPEED)) { + setSpeed(angle(direction), mSpeed); setAngle(direction); } diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index eb0b858..5a196d0 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -9,8 +9,11 @@ #define DG_BULLET_H_ #include "../particle/Particle.h" +#include "../util/String.h" +#include "../util/Yaml.h" class Particle; +class Yaml; /** * Bullet particle fired by a weapon, may damage actors. @@ -18,8 +21,8 @@ class Particle; class Bullet : public Particle { // Public functions. public: - Bullet(const Vector2f& position, b2World& world, const std::shared_ptr& texture, - Physical& shooter, float direction, int damage); + Bullet(const Vector2f& position, b2World& world, Physical& shooter, float direction, + const Yaml& config); void onCollide(Physical& other, uint16 category); bool doesCollide(Physical& other); @@ -30,9 +33,12 @@ public: // Private variables. private: - static const float SPEED; //< If speed is too low, bullets push each other away on insert. + static const String KEY_DAMAGE; + static const String KEY_SPEED; + Physical& mShooter; - const int mDamage; + const int mDamage; + const float mSpeed; }; #endif /* DG_BULLET_H_ */ diff --git a/source/items/Weapon.cpp b/source/items/Weapon.cpp index 792217d..5ab86c0 100755 --- a/source/items/Weapon.cpp +++ b/source/items/Weapon.cpp @@ -13,21 +13,17 @@ #include "../util/Collection.h" #include "../effects/Bullet.h" -#include "../util/Loader.h" -#include "../util/ResourceManager.h" -const String Weapon::KEY_DAMAGE = "damage"; +const String Weapon::KEY_BULLET = "bullet"; Weapon::Weapon(const Instances& instances, Physical& holder, const Yaml& config) : Emitter(instances.collection), mHolder(holder), - mBulletTexture(ResourceManager::i() - .acquire(Loader::i().fromFile("bullet.png"))), mWorld(instances.world), mOffset(0, std::max(mHolder.getSize().x, mHolder.getSize().y) / 2 + b2_linearSlop + std::max(Bullet::SIZE.x, Bullet::SIZE.y) / 2), - mDamage(config.get(KEY_DAMAGE)) { + mBullet(config.get(KEY_BULLET)) { } /** @@ -44,6 +40,6 @@ Weapon::createParticle() { // Minus to account for positive y-axis going downwards in SFML. Vector2f offset(- mOffset); thor::rotate(offset, mHolder.getAngle()); - return std::shared_ptr(new Bullet(mHolder.getPosition() + offset, - mWorld, mBulletTexture, mHolder, mHolder.getAngle(), mDamage)); + return std::shared_ptr(new Bullet(mHolder.getPosition() + offset, mWorld, + mHolder, mHolder.getAngle(), Yaml(mBullet))); } diff --git a/source/items/Weapon.h b/source/items/Weapon.h index edd82b3..b4226fe 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -18,6 +18,7 @@ class Emitter; class Instances; class Physical; +class Yaml; /** * Loading mechanism: @@ -37,14 +38,13 @@ protected: // Private variables. private: - static const String KEY_DAMAGE; + static const String KEY_BULLET; Physical& mHolder; - std::shared_ptr mBulletTexture; b2World& mWorld; const Vector2f mOffset; //< Offset to the point where bullets are inserted (from holder center). - const int mDamage; + const String mBullet; }; #endif /* DG_WEAPON_H_ */ diff --git a/source/main.cpp b/source/main.cpp index 291af6f..2c0941d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,7 +7,6 @@ #include "Game.h" #include "util/Loader.h" - #include "util/Yaml.h" /**