Added Health Orb to be randomly dropped by Characters and heal player.

This commit is contained in:
Felix Ableitner 2013-09-02 21:58:11 +02:00
parent b526a291d7
commit 9c4feb7636
6 changed files with 72 additions and 18 deletions

View file

@ -23,3 +23,4 @@ Player/Enemy (modified): http://opengameart.org/content/top-down-runner
Tiles (modified): http://opengameart.org/content/metalstone-textures
Item: http://opengameart.org/content/random-adventure-kit
Crosshair: http://opengameart.org/content/20-crosshairs-for-re
Health Orb: http://opengameart.org/content/magic-orbs

BIN
res/textures/health_orb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -12,6 +12,7 @@
#include "generator/Generator.h"
#include "sprites/Enemy.h"
#include "sprites/Player.h"
#include "sprites/items/HealthOrb.h"
#include "util/Loader.h"
#include "util/Yaml.h"
@ -126,7 +127,11 @@ Game::updateGui() {
mWindow.getSize().y - mRightGadget->getSize().y);
auto item = mWorld.getClosestItem(mPlayer->getPosition());
if (item.get() != nullptr) {
if (std::dynamic_pointer_cast<HealthOrb>(item)) {
mPlayer->onDamage(- HealthOrb::AMOUNT_HEALED);
mWorld.remove(item);
}
else if (item) {
mPickupInstruction->setText("F - pick up " + item->getName());
mPickupInstruction->setPosition(
mWindow.getSize().x / 2 - mPickupInstruction->getSize().x / 2,

View file

@ -9,6 +9,7 @@
#include <Thor/Vectors.hpp>
#include "../items/HealthOrb.h"
#include "../items/Weapon.h"
#include "../Corpse.h"
#include "../../util/Log.h"
@ -103,23 +104,29 @@ void
Character::onDeath() {
mWorld.insert(std::shared_ptr<Sprite>(new Corpse(getPosition())));
if (rand() % 2)
dropItem(std::make_shared<HealthOrb>());
else
switch (rand() % 3) {
case 0:
// To avoid weapons continuing to fire after drop and pickup.
mFirstWeapon->releaseTrigger();
dropItem(mFirstWeapon);
break;
case 1:
// Same here.
mSecondWeapon->releaseTrigger();
dropItem(mSecondWeapon);
break;
case 2:
if (mLeftGadget)
dropItem(mLeftGadget);
else if (mRightGadget)
break;
case 3:
if (mRightGadget)
dropItem(mRightGadget);
break;
}
// To avoid weapons continuing to fire after drop and pickup.
mFirstWeapon->releaseTrigger();
mSecondWeapon->releaseTrigger();
}
/**

View file

@ -0,0 +1,19 @@
/*
* HealthOrb.cpp
*
* Created on: 02.09.2013
* Author: Felix
*/
#include "HealthOrb.h"
HealthOrb::HealthOrb() :
Item(Vector2i(32, 32), "health_orb.png") {
}
std::string
HealthOrb::getName() const {
return "Health Orb";
}

View file

@ -0,0 +1,22 @@
/*
* HealthOrb.h
*
* Created on: 02.09.2013
* Author: Felix
*/
#ifndef DG_HEALTHORB_H_
#define DG_HEALTHORB_H_
#include "Item.h"
class HealthOrb : public Item {
public:
static const int AMOUNT_HEALED = 50;
public:
HealthOrb();
std::string getName() const;
};
#endif /* DG_HEALTHORB_H_ */