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
texture: shield.png
size: [75, 5]
cooldown: 5000

View file

@ -12,9 +12,13 @@
#include "Shield.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"),
mName(name) {
mName(name),
mCooldown(sf::milliseconds(cooldown)) {
}
/**
@ -38,7 +42,7 @@ void
Gadget::use(Character& character) {
if (mCooldownTimer.isExpired()) {
onUse(character);
mCooldownTimer.restart(getCooldownTime());
mCooldownTimer.restart(mCooldown);
}
}

View file

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

View file

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

View file

@ -1,15 +1,17 @@
/*
* SlowHeal.h
* Heal.h
*
* Created on: 06.07.2013
* Author: Felix
*/
#ifndef DG_SLOWHEAL_H_
#define DG_SLOWHEAL_H_
#ifndef DG_HEAL_H_
#define DG_HEAL_H_
#include "Gadget.h"
#include "../../util/Yaml.h"
class Heal : public Gadget {
public:
Heal();
@ -17,13 +19,17 @@ public:
protected:
void onUse(Character& character) override;
void onThink(int elapsed) override;
sf::Time getCooldownTime() const override;
GadgetType getType() const override;
private:
static const Yaml CONFIG;
const int mHealedTotal;
const sf::Time mTimePerPoint;
int mHealed;
Character* mCharacter;
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 "../../World.h"
const Yaml RingOfFire::CONFIG("res/yaml/ring_of_fire.yaml");
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),
mBullet("bullet.yaml") {
mBullet(CONFIG.get("bullet", std::string())) {
}
void
@ -26,8 +33,8 @@ RingOfFire::onUse(Character& character) {
void
RingOfFire::onThink(int elapsed) {
if (mCurrentWave < WAVES_PER_USE && mTimer.isExpired()) {
for (int angle = mCurrentWave * 10; angle <= 360; angle += 30) {
if (mCurrentWave < mWavesPerUse && mTimer.isExpired()) {
for (int angle = mCurrentWave * 10; angle <= 360; angle += 360 / mBulletsPerWave) {
Vector2f direction(thor::rotatedVector(mCharacter->getDirection(), (float) angle) *
mCharacter->getRadius());
@ -36,16 +43,11 @@ RingOfFire::onThink(int elapsed) {
mWorld.insert(projectile);
}
mTimer.restart(sf::milliseconds(500));
mTimer.restart(mDelay);
mCurrentWave++;
}
}
sf::Time
RingOfFire::getCooldownTime() const {
return sf::seconds(5);
}
Gadget::GadgetType
RingOfFire::getType() const {
return GadgetType::RINGOFFIRE;

View file

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

View file

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

View file

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