Moved damage, speed from bullet to weapon, added pistol, rifle.

This commit is contained in:
Felix Ableitner 2013-06-25 18:28:18 +02:00
parent b5b3ea33f8
commit db662808c2
9 changed files with 39 additions and 11 deletions

View file

@ -1,6 +1,8 @@
name: Assault Rifle
bullet: bullet.yaml
projectile_speed: 1000
damage: 15
fire_interval: 150
reload_time: 2000
automatic: true

View file

@ -1,7 +1,5 @@
name: Bullet
texture: bullet.png
damage: 10
radius: 5
size: [3, 10]
speed: 1000
size: [3, 10]

View file

@ -0,0 +1,10 @@
name: Pistol
bullet: bullet.yaml
projectile_speed: 1000
damage: 10
fire_interval: 200
reload_time: 1500
automatic: false
magazine_size: 9
max_total_ammo: 150

View file

@ -5,5 +5,5 @@ health: 100
speed: 100
radius: 25
size: [50, 50]
weapon: assault_rifle.yaml
weapon: rifle.yaml
faction: 0

10
resources/yaml/rifle.yaml Normal file
View file

@ -0,0 +1,10 @@
name: Rifle
bullet: bullet.yaml
projectile_speed: 1000
damage: 25
fire_interval: 400
reload_time: 2000
automatic: false
magazine_size: 15
max_total_ammo: 200

View file

@ -21,12 +21,13 @@
* @param texture Texture to display for bullet.
*/
Bullet::Bullet(const sf::Vector2f& position, Character& shooter,
sf::Vector2f direction, const Yaml& config) :
sf::Vector2f direction, const Yaml& config, float speed,
float damage) :
Particle(position, CATEGORY_PARTICLE, ~CATEGORY_PARTICLE,
config, thor::rotatedVector(direction, -90.0f)),
mShooter(shooter),
mDamage(config.get("damage", 0)),
mSpeed(config.get("speed", 0.0f)) {
mDamage(damage),
mSpeed(speed) {
setSpeed(thor::rotatedVector(direction, -90.0f), mSpeed);
}

View file

@ -19,7 +19,8 @@ class Yaml;
class Bullet : public Particle {
public:
explicit Bullet(const sf::Vector2f& position, Character& shooter,
sf::Vector2f direction, const Yaml& config);
sf::Vector2f direction, const Yaml& config, float speed,
float damage);
void onCollide(std::shared_ptr<Sprite> other);

View file

@ -16,7 +16,9 @@
Weapon::Weapon(World& world, Character& holder, const Yaml& config) :
Emitter(world),
mHolder(holder),
mBullet(config.get("bullet", std::string("bullet.yaml"))),
mProjectile(config.get("bullet", std::string("bullet.yaml"))),
mDamage(config.get("damage", 0)),
mProjectileSpeed(config.get("projectile_speed", 0.0f)),
mFireInterval(config.get("fire_interval", 0)),
mReloadTime(config.get("reload_time", 0)),
mFire(false),
@ -82,7 +84,8 @@ Weapon::createParticle() {
sf::Vector2f offset(0, - mHolder.getRadius());
thor::rotate(offset, thor::polarAngle(mHolder.getDirection()));
return std::shared_ptr<Sprite>(new Bullet(mHolder.getPosition() + offset,
mHolder, mHolder.getDirection(), Yaml(mBullet)));
mHolder, mHolder.getDirection(), mProjectile, mProjectileSpeed,
mDamage));
}
int

View file

@ -15,6 +15,7 @@
#include <Thor/Time.hpp>
#include "../particle/Emitter.h"
#include "../util/Yaml.h"
class Character;
class World;
@ -44,7 +45,9 @@ private:
Character& mHolder;
thor::Timer mTimer;
const std::string mBullet;
const Yaml mProjectile;
const int mDamage;
const float mProjectileSpeed;
const int mFireInterval;
const int mReloadTime;
bool mFire;