Moved Health Orb config to yaml.
This commit is contained in:
parent
0812287502
commit
7df94496e0
4 changed files with 29 additions and 9 deletions
7
res/yaml/health_orb.yaml
Normal file
7
res/yaml/health_orb.yaml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
name: Health Orb
|
||||||
|
|
||||||
|
texture: health_orb.png
|
||||||
|
|
||||||
|
size: [32, 32]
|
||||||
|
|
||||||
|
amount_healed: 50
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_ */
|
||||||
|
|
Reference in a new issue