Moved Health Orb config to yaml.

This commit is contained in:
Felix Ableitner 2013-09-03 16:05:36 +02:00
parent 0812287502
commit 7df94496e0
4 changed files with 29 additions and 9 deletions

7
res/yaml/health_orb.yaml Normal file
View File

@ -0,0 +1,7 @@
name: Health Orb
texture: health_orb.png
size: [32, 32]
amount_healed: 50

View File

@ -127,8 +127,9 @@ Game::updateGui() {
mWindow.getSize().y - mRightGadget->getSize().y); mWindow.getSize().y - mRightGadget->getSize().y);
auto item = mWorld.getClosestItem(mPlayer->getPosition()); auto item = mWorld.getClosestItem(mPlayer->getPosition());
if (std::dynamic_pointer_cast<HealthOrb>(item)) { auto orb = std::dynamic_pointer_cast<HealthOrb>(item);
mPlayer->onDamage(- HealthOrb::AMOUNT_HEALED); if (orb) {
mPlayer->onDamage(- orb->getAmountHealed());
mWorld.remove(item); mWorld.remove(item);
} }
else if (item) { else if (item) {

View File

@ -7,13 +7,20 @@
#include "HealthOrb.h" #include "HealthOrb.h"
HealthOrb::HealthOrb() : const Yaml HealthOrb::CONFIG("res/yaml/health_orb.yaml");
Item(Vector2i(32, 32), "health_orb.png") {
HealthOrb::HealthOrb() :
Item(CONFIG.get("size", Vector2i()), CONFIG.get("texture", std::string())),
mName(CONFIG.get("name", std::string())),
mAmountHealed(CONFIG.get("amount_healed", 0)) {
}
int
HealthOrb::getAmountHealed() const {
return mAmountHealed;
} }
std::string std::string
HealthOrb::getName() const { HealthOrb::getName() const {
return "Health Orb"; return mName;
} }

View File

@ -10,13 +10,18 @@
#include "Item.h" #include "Item.h"
class HealthOrb : public Item { #include "../../util/Yaml.h"
public:
static const int AMOUNT_HEALED = 50;
class HealthOrb : public Item {
public: public:
HealthOrb(); HealthOrb();
std::string getName() const; std::string getName() const;
int getAmountHealed() const;
private:
static const Yaml CONFIG;
const std::string mName;
const int mAmountHealed;
}; };
#endif /* DG_HEALTHORB_H_ */ #endif /* DG_HEALTHORB_H_ */