Added option for different bullet spread during movement.

This commit is contained in:
Felix Ableitner 2013-06-25 21:35:58 +02:00
parent e04d684352
commit ef0fa839b9
4 changed files with 12 additions and 5 deletions

View file

@ -8,4 +8,5 @@ reload_time: 2000
automatic: true
magazine_size: 30
max_total_ammo: 270
spread: 2.0
spread: 2.0
spread_moving: 5.0

View file

@ -3,9 +3,10 @@ name: Machine Gun
bullet: bullet.yaml
projectile_speed: 1000
damage: 20
fire_interval: 100
fire_interval: 150
reload_time: 5000
automatic: true
magazine_size: 60
max_total_ammo: 400
spread: 5.0
spread: 5.0
spread_moving: 15.0

View file

@ -30,7 +30,8 @@ Weapon::Weapon(World& world, Character& holder, const Yaml& config) :
mPellets(config.get("pellets", 0)),
mPelletSpread(config.get("pellet_spread", 0.0f)),
mReloadSingle(config.get("reload_single", false)),
mSpread(config.get("spread", 0.0f)) {
mSpread(config.get("spread", 0.0f)),
mSpreadMoving(config.get("spread_moving", 0.0f)) {
}
/**
@ -135,7 +136,10 @@ Weapon::insertProjectile(float angle) {
sf::Vector2f offset(0, - mHolder.getRadius());
thor::rotate(offset, thor::polarAngle(mHolder.getDirection()));
std::uniform_real_distribution<float> distribution(- mSpread, mSpread);
float spread = (mHolder.getSpeed() == sf::Vector2f())
? mSpread
: mSpreadMoving;
std::uniform_real_distribution<float> distribution(- spread, spread);
angle += distribution(mGenerator);
//float random = ((float) rand()) / (float) RAND_MAX;

View file

@ -58,6 +58,7 @@ private:
const float mPelletSpread;
const bool mReloadSingle;
const float mSpread;
const float mSpreadMoving;
std::default_random_engine mGenerator;
};