From db662808c2a1fe5af0ddeb14046dcebd6dda6477 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 25 Jun 2013 18:28:18 +0200 Subject: [PATCH] Moved damage, speed from bullet to weapon, added pistol, rifle. --- resources/yaml/assault_rifle.yaml | 2 ++ resources/yaml/bullet.yaml | 4 +--- resources/yaml/pistol.yaml | 10 ++++++++++ resources/yaml/player.yaml | 2 +- resources/yaml/rifle.yaml | 10 ++++++++++ source/effects/Bullet.cpp | 7 ++++--- source/effects/Bullet.h | 3 ++- source/items/Weapon.cpp | 7 +++++-- source/items/Weapon.h | 5 ++++- 9 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 resources/yaml/pistol.yaml create mode 100644 resources/yaml/rifle.yaml diff --git a/resources/yaml/assault_rifle.yaml b/resources/yaml/assault_rifle.yaml index 9b291b8..39f79de 100644 --- a/resources/yaml/assault_rifle.yaml +++ b/resources/yaml/assault_rifle.yaml @@ -1,6 +1,8 @@ name: Assault Rifle bullet: bullet.yaml +projectile_speed: 1000 +damage: 15 fire_interval: 150 reload_time: 2000 automatic: true diff --git a/resources/yaml/bullet.yaml b/resources/yaml/bullet.yaml index 075d090..d7e2876 100644 --- a/resources/yaml/bullet.yaml +++ b/resources/yaml/bullet.yaml @@ -1,7 +1,5 @@ name: Bullet texture: bullet.png -damage: 10 radius: 5 -size: [3, 10] -speed: 1000 \ No newline at end of file +size: [3, 10] \ No newline at end of file diff --git a/resources/yaml/pistol.yaml b/resources/yaml/pistol.yaml new file mode 100644 index 0000000..43f5983 --- /dev/null +++ b/resources/yaml/pistol.yaml @@ -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 \ No newline at end of file diff --git a/resources/yaml/player.yaml b/resources/yaml/player.yaml index 034bf48..3e7cf13 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: assault_rifle.yaml +weapon: rifle.yaml faction: 0 \ No newline at end of file diff --git a/resources/yaml/rifle.yaml b/resources/yaml/rifle.yaml new file mode 100644 index 0000000..443d432 --- /dev/null +++ b/resources/yaml/rifle.yaml @@ -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 \ No newline at end of file diff --git a/source/effects/Bullet.cpp b/source/effects/Bullet.cpp index 10ec1f1..11d55e1 100755 --- a/source/effects/Bullet.cpp +++ b/source/effects/Bullet.cpp @@ -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); } diff --git a/source/effects/Bullet.h b/source/effects/Bullet.h index e9531c2..5c88dc8 100755 --- a/source/effects/Bullet.h +++ b/source/effects/Bullet.h @@ -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 other); diff --git a/source/items/Weapon.cpp b/source/items/Weapon.cpp index e3aab1d..ba80657 100755 --- a/source/items/Weapon.cpp +++ b/source/items/Weapon.cpp @@ -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(new Bullet(mHolder.getPosition() + offset, - mHolder, mHolder.getDirection(), Yaml(mBullet))); + mHolder, mHolder.getDirection(), mProjectile, mProjectileSpeed, + mDamage)); } int diff --git a/source/items/Weapon.h b/source/items/Weapon.h index c424786..80ca7af 100755 --- a/source/items/Weapon.h +++ b/source/items/Weapon.h @@ -15,6 +15,7 @@ #include #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;