Added bullet spread and Heavy Machine Gun.
This commit is contained in:
parent
6923092c3b
commit
e04d684352
5 changed files with 29 additions and 10 deletions
|
@ -7,4 +7,5 @@ fire_interval: 150
|
|||
reload_time: 2000
|
||||
automatic: true
|
||||
magazine_size: 30
|
||||
max_total_ammo: 270
|
||||
max_total_ammo: 270
|
||||
spread: 2.0
|
11
resources/yaml/hmg.yaml
Normal file
11
resources/yaml/hmg.yaml
Normal file
|
@ -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
|
|
@ -5,5 +5,5 @@ health: 100
|
|||
speed: 100
|
||||
radius: 25
|
||||
size: [50, 50]
|
||||
weapon: shotgun.yaml
|
||||
weapon: hmg.yaml
|
||||
faction: 0
|
|
@ -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<float> 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<Sprite> projectile(new Bullet(mHolder.getPosition() + offset,
|
||||
mHolder, direction, mProjectile, mProjectileSpeed,
|
||||
mDamage));
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define DG_WEAPON_H_
|
||||
|
||||
#include <string>
|
||||
#include <random>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue