Moved Gadget parameters to yaml.

This commit is contained in:
Felix Ableitner 2013-09-03 01:17:03 +02:00
parent 831975cf10
commit 0812287502
11 changed files with 91 additions and 44 deletions

10
res/yaml/heal.yaml Normal file
View file

@ -0,0 +1,10 @@
name: Heal
# Milliseconds between each use.
cooldown: 5000
# Hit points restored with each use (total).
amount_healed: 50
# Time in milliseconds to restore one hitpoint.
time_per_point: 75

View file

@ -0,0 +1,18 @@
name: Ring of Fire
# Milliseconds between each use.
cooldown: 5000
bullet: bullet.yaml
# Number of times a new ring of bullets is unleashed (per item use).
waves_per_use: 3
# Degrees by which each new wave is offset from the previous one.
angle_offset: 10
# Number of bullets in each ring.
bullets_per_wave: 12
# Milliseconds between two waves.
delay: 500

View file

@ -1,3 +1,7 @@
name: Shield name: Shield
texture: shield.png texture: shield.png
size: [75, 5]
size: [75, 5]
cooldown: 5000

View file

@ -12,9 +12,13 @@
#include "Shield.h" #include "Shield.h"
#include "RingOfFire.h" #include "RingOfFire.h"
Gadget::Gadget(std::string name) : /**
* @param cooldown Time in milliseconds after which the gadget can be used again.
*/
Gadget::Gadget(std::string name, int cooldown) :
Item(sf::Vector2f(32, 32), "item.png"), Item(sf::Vector2f(32, 32), "item.png"),
mName(name) { mName(name),
mCooldown(sf::milliseconds(cooldown)) {
} }
/** /**
@ -38,7 +42,7 @@ void
Gadget::use(Character& character) { Gadget::use(Character& character) {
if (mCooldownTimer.isExpired()) { if (mCooldownTimer.isExpired()) {
onUse(character); onUse(character);
mCooldownTimer.restart(getCooldownTime()); mCooldownTimer.restart(mCooldown);
} }
} }

View file

@ -28,7 +28,7 @@ public:
}; };
public: public:
Gadget(std::string name); Gadget(std::string name, int cooldown);
static std::shared_ptr<Gadget> getGadget(World& world, GadgetType type); static std::shared_ptr<Gadget> getGadget(World& world, GadgetType type);
void use(Character& character); void use(Character& character);
virtual void onThink(int elapsed) = 0; virtual void onThink(int elapsed) = 0;
@ -37,13 +37,13 @@ public:
protected: protected:
virtual void onUse(Character& character) = 0; virtual void onUse(Character& character) = 0;
virtual sf::Time getCooldownTime() const = 0;
protected: protected:
thor::Timer mCooldownTimer; thor::Timer mCooldownTimer;
private: private:
std::string mName; const std::string mName;
const sf::Time mCooldown;
}; };
#endif /* DG_GADGET_H_ */ #endif /* DG_GADGET_H_ */

View file

@ -1,5 +1,5 @@
/* /*
* SlowHeal.cpp * Heal.cpp
* *
* Created on: 06.07.2013 * Created on: 06.07.2013
* Author: Felix * Author: Felix
@ -9,30 +9,30 @@
#include "../abstract/Character.h" #include "../abstract/Character.h"
const Yaml Heal::CONFIG("res/yaml/heal.yaml");
Heal::Heal() : Heal::Heal() :
Gadget("Heal") { Gadget(CONFIG.get("name", std::string()), CONFIG.get("cooldown", 0)),
mHealedTotal(CONFIG.get("amount_healed", 0)),
mTimePerPoint(sf::milliseconds(CONFIG.get("time_healing", 0))),
mHealed(mHealedTotal + 1) {
} }
void void
Heal::onUse(Character& character) { Heal::onUse(Character& character) {
mCharacter = &character; mCharacter = &character;
mHealedTotal = 0; mHealed = 0;
} }
void void
Heal::onThink(int elapsed) { Heal::onThink(int elapsed) {
if (mHealedTotal < 50 && mTimer.isExpired()) { if (mHealed < mHealedTotal && mTimer.isExpired()) {
mCharacter->onDamage(-1); mCharacter->onDamage(-1);
mHealedTotal += 1; mHealed++;
mTimer.restart(sf::milliseconds(75)); mTimer.restart(mTimePerPoint);
} }
} }
sf::Time
Heal::getCooldownTime() const {
return sf::seconds(5);
}
Gadget::GadgetType Gadget::GadgetType
Heal::getType() const { Heal::getType() const {
return GadgetType::HEAL; return GadgetType::HEAL;

View file

@ -1,15 +1,17 @@
/* /*
* SlowHeal.h * Heal.h
* *
* Created on: 06.07.2013 * Created on: 06.07.2013
* Author: Felix * Author: Felix
*/ */
#ifndef DG_SLOWHEAL_H_ #ifndef DG_HEAL_H_
#define DG_SLOWHEAL_H_ #define DG_HEAL_H_
#include "Gadget.h" #include "Gadget.h"
#include "../../util/Yaml.h"
class Heal : public Gadget { class Heal : public Gadget {
public: public:
Heal(); Heal();
@ -17,13 +19,17 @@ public:
protected: protected:
void onUse(Character& character) override; void onUse(Character& character) override;
void onThink(int elapsed) override; void onThink(int elapsed) override;
sf::Time getCooldownTime() const override;
GadgetType getType() const override; GadgetType getType() const override;
private: private:
static const Yaml CONFIG;
const int mHealedTotal;
const sf::Time mTimePerPoint;
int mHealed;
Character* mCharacter; Character* mCharacter;
thor::Timer mTimer; thor::Timer mTimer;
int mHealedTotal = 50;
}; };
#endif /* DG_SLOWHEAL_H_ */ #endif /* DG_HEAL_H_ */

View file

@ -12,10 +12,17 @@
#include "../effects/Bullet.h" #include "../effects/Bullet.h"
#include "../../World.h" #include "../../World.h"
const Yaml RingOfFire::CONFIG("res/yaml/ring_of_fire.yaml");
RingOfFire::RingOfFire(World& world) : RingOfFire::RingOfFire(World& world) :
Gadget("Ring of Fire"), Gadget(CONFIG.get("name", std::string()), CONFIG.get("cooldown", 0)),
mWavesPerUse(CONFIG.get("waves_per_use", 0)),
mAngleOffset(CONFIG.get("angle_offset", 0.0f)),
mBulletsPerWave(CONFIG.get("bullets_per_wave", 0)),
mDelay(sf::milliseconds(CONFIG.get("delay", 0))),
mCurrentWave(mWavesPerUse + 1),
mWorld(world), mWorld(world),
mBullet("bullet.yaml") { mBullet(CONFIG.get("bullet", std::string())) {
} }
void void
@ -26,8 +33,8 @@ RingOfFire::onUse(Character& character) {
void void
RingOfFire::onThink(int elapsed) { RingOfFire::onThink(int elapsed) {
if (mCurrentWave < WAVES_PER_USE && mTimer.isExpired()) { if (mCurrentWave < mWavesPerUse && mTimer.isExpired()) {
for (int angle = mCurrentWave * 10; angle <= 360; angle += 30) { for (int angle = mCurrentWave * 10; angle <= 360; angle += 360 / mBulletsPerWave) {
Vector2f direction(thor::rotatedVector(mCharacter->getDirection(), (float) angle) * Vector2f direction(thor::rotatedVector(mCharacter->getDirection(), (float) angle) *
mCharacter->getRadius()); mCharacter->getRadius());
@ -36,16 +43,11 @@ RingOfFire::onThink(int elapsed) {
mWorld.insert(projectile); mWorld.insert(projectile);
} }
mTimer.restart(sf::milliseconds(500)); mTimer.restart(mDelay);
mCurrentWave++; mCurrentWave++;
} }
} }
sf::Time
RingOfFire::getCooldownTime() const {
return sf::seconds(5);
}
Gadget::GadgetType Gadget::GadgetType
RingOfFire::getType() const { RingOfFire::getType() const {
return GadgetType::RINGOFFIRE; return GadgetType::RINGOFFIRE;

View file

@ -22,12 +22,16 @@ public:
protected: protected:
void onUse(Character& character) override; void onUse(Character& character) override;
void onThink(int elapsed) override; void onThink(int elapsed) override;
sf::Time getCooldownTime() const override;
GadgetType getType() const override; GadgetType getType() const override;
private: private:
static constexpr int WAVES_PER_USE = 3; static const Yaml CONFIG;
int mCurrentWave = WAVES_PER_USE + 1; const int mWavesPerUse;
const int mAngleOffset;
const int mBulletsPerWave;
const sf::Time mDelay;
int mCurrentWave;
Character* mCharacter; Character* mCharacter;
thor::Timer mTimer; thor::Timer mTimer;

View file

@ -11,8 +11,10 @@
#include "../RotatingShield.h" #include "../RotatingShield.h"
#include "../../World.h" #include "../../World.h"
const Yaml Shield::CONFIG("res/yaml/rotating_shield.yaml");
Shield::Shield() : Shield::Shield() :
Gadget("Shield") { Gadget(CONFIG.get("name", std::string()), CONFIG.get("cooldown", 0)) {
} }
void void
@ -34,11 +36,6 @@ Shield::onThink(int elapsed) {
} }
} }
sf::Time
Shield::getCooldownTime() const {
return sf::seconds(10);
}
Shield::GadgetType Shield::GadgetType
Shield::getType() const { Shield::getType() const {
return GadgetType::SHIELD; return GadgetType::SHIELD;

View file

@ -10,6 +10,8 @@
#include "Gadget.h" #include "Gadget.h"
#include "../../util/Yaml.h"
class RotatingShield; class RotatingShield;
class Sprite; class Sprite;
@ -20,10 +22,10 @@ public:
protected: protected:
void onUse(Character& character) override; void onUse(Character& character) override;
void onThink(int elapsed) override; void onThink(int elapsed) override;
sf::Time getCooldownTime() const override;
GadgetType getType() const override; GadgetType getType() const override;
private: private:
static const Yaml CONFIG;
Character* mCharacter; Character* mCharacter;
std::shared_ptr<RotatingShield> mRotatingShield; std::shared_ptr<RotatingShield> mRotatingShield;
}; };