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);
|
||||
|
||||
auto item = mWorld.getClosestItem(mPlayer->getPosition());
|
||||
if (std::dynamic_pointer_cast<HealthOrb>(item)) {
|
||||
mPlayer->onDamage(- HealthOrb::AMOUNT_HEALED);
|
||||
auto orb = std::dynamic_pointer_cast<HealthOrb>(item);
|
||||
if (orb) {
|
||||
mPlayer->onDamage(- orb->getAmountHealed());
|
||||
mWorld.remove(item);
|
||||
}
|
||||
else if (item) {
|
||||
|
|
|
@ -7,13 +7,20 @@
|
|||
|
||||
#include "HealthOrb.h"
|
||||
|
||||
HealthOrb::HealthOrb() :
|
||||
Item(Vector2i(32, 32), "health_orb.png") {
|
||||
const Yaml HealthOrb::CONFIG("res/yaml/health_orb.yaml");
|
||||
|
||||
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
|
||||
HealthOrb::getName() const {
|
||||
return "Health Orb";
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,13 +10,18 @@
|
|||
|
||||
#include "Item.h"
|
||||
|
||||
class HealthOrb : public Item {
|
||||
public:
|
||||
static const int AMOUNT_HEALED = 50;
|
||||
#include "../../util/Yaml.h"
|
||||
|
||||
class HealthOrb : public Item {
|
||||
public:
|
||||
HealthOrb();
|
||||
std::string getName() const;
|
||||
int getAmountHealed() const;
|
||||
|
||||
private:
|
||||
static const Yaml CONFIG;
|
||||
const std::string mName;
|
||||
const int mAmountHealed;
|
||||
};
|
||||
|
||||
#endif /* DG_HEALTHORB_H_ */
|
||||
|
|
Reference in a new issue