diff --git a/resources/yaml/assault_rifle.yaml b/resources/yaml/assault_rifle.yaml index 39f79de..459b705 100644 --- a/resources/yaml/assault_rifle.yaml +++ b/resources/yaml/assault_rifle.yaml @@ -7,4 +7,5 @@ fire_interval: 150 reload_time: 2000 automatic: true magazine_size: 30 -max_total_ammo: 270 \ No newline at end of file +max_total_ammo: 270 +spread: 2.0 \ No newline at end of file diff --git a/resources/yaml/hmg.yaml b/resources/yaml/hmg.yaml new file mode 100644 index 0000000..57a80d5 --- /dev/null +++ b/resources/yaml/hmg.yaml @@ -0,0 +1,11 @@ +name: Machine Gun + +bullet: bullet.yaml +projectile_speed: 1000 +damage: 20 +fire_interval: 100 +reload_time: 5000 +automatic: true +magazine_size: 60 +max_total_ammo: 400 +spread: 5.0 \ No newline at end of file diff --git a/resources/yaml/player.yaml b/resources/yaml/player.yaml index 28c3f25..def53a2 100644 --- a/resources/yaml/player.yaml +++ b/resources/yaml/player.yaml @@ -5,5 +5,5 @@ health: 100 speed: 100 radius: 25 size: [50, 50] -weapon: shotgun.yaml +weapon: hmg.yaml faction: 0 \ No newline at end of file diff --git a/source/items/Weapon.cpp b/source/items/Weapon.cpp index baa73cd..48148c8 100755 --- a/source/items/Weapon.cpp +++ b/source/items/Weapon.cpp @@ -27,9 +27,10 @@ Weapon::Weapon(World& world, Character& holder, const Yaml& config) : mMagazineAmmo(mMagazineSize), mMaxTotalAmmo(config.get("max_total_ammo", 0)), mTotalAmmo(mMaxTotalAmmo), - mPellets(config.get("pellets", 1)), + mPellets(config.get("pellets", 0)), mPelletSpread(config.get("pellet_spread", 0.0f)), - mReloadSingle(config.get("reload_single", false)) { + mReloadSingle(config.get("reload_single", false)), + mSpread(config.get("spread", 0.0f)) { } /** @@ -97,7 +98,8 @@ Weapon::fire() { mMagazineAmmo--; - if (mPellets == 0) insertProjectile(0.0f); + if (mPellets == 0) + insertProjectile(0.0f); else for (int i = - mPellets / 2; i < mPellets / 2; i++) { insertProjectile(i * mPelletSpread); @@ -132,7 +134,14 @@ Weapon::insertProjectile(float angle) { // Minus to account for positive y-axis going downwards in SFML. sf::Vector2f offset(0, - mHolder.getRadius()); thor::rotate(offset, thor::polarAngle(mHolder.getDirection())); + + std::uniform_real_distribution distribution(- mSpread, mSpread); + angle += distribution(mGenerator); + + //float random = ((float) rand()) / (float) RAND_MAX; + //angle += random * 2 * mSpread - mSpread; sf::Vector2f direction(thor::rotatedVector(mHolder.getDirection(), angle)); + std::shared_ptr projectile(new Bullet(mHolder.getPosition() + offset, mHolder, direction, mProjectile, mProjectileSpeed, mDamage)); diff --git a/source/items/Weapon.h b/source/items/Weapon.h index 5653c31..2988b6a 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -9,6 +9,7 @@ #define DG_WEAPON_H_ #include +#include #include @@ -21,11 +22,6 @@ class World; class Particle; class Yaml; -/** - * Loading mechanism: - * - pass enum value and load mapped xml - * - pass xml filename - */ class Weapon { public: explicit Weapon(World& world, Character& holder, const Yaml& config); @@ -61,6 +57,8 @@ private: const int mPellets; const float mPelletSpread; const bool mReloadSingle; + const float mSpread; + std::default_random_engine mGenerator; };