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())));
switch (rand() % 3) {
case 0:
dropItem(mFirstWeapon);
break;
case 1:
dropItem(mSecondWeapon);
break;
case 2:
if (mLeftGadget)
dropItem(mLeftGadget);
else if (mRightGadget)
dropItem(mRightGadget);
}
// To avoid weapons continuing to fire after drop and pickup.
mFirstWeapon->releaseTrigger();
mSecondWeapon->releaseTrigger();
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);
break;
case 3:
if (mRightGadget)
dropItem(mRightGadget);
break;
}
}
/**

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_ */