Added Health Orb to be randomly dropped by Characters and heal player.
This commit is contained in:
parent
b526a291d7
commit
9c4feb7636
6 changed files with 72 additions and 18 deletions
|
@ -23,3 +23,4 @@ Player/Enemy (modified): http://opengameart.org/content/top-down-runner
|
||||||
Tiles (modified): http://opengameart.org/content/metalstone-textures
|
Tiles (modified): http://opengameart.org/content/metalstone-textures
|
||||||
Item: http://opengameart.org/content/random-adventure-kit
|
Item: http://opengameart.org/content/random-adventure-kit
|
||||||
Crosshair: http://opengameart.org/content/20-crosshairs-for-re
|
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
BIN
res/textures/health_orb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
|
@ -12,6 +12,7 @@
|
||||||
#include "generator/Generator.h"
|
#include "generator/Generator.h"
|
||||||
#include "sprites/Enemy.h"
|
#include "sprites/Enemy.h"
|
||||||
#include "sprites/Player.h"
|
#include "sprites/Player.h"
|
||||||
|
#include "sprites/items/HealthOrb.h"
|
||||||
#include "util/Loader.h"
|
#include "util/Loader.h"
|
||||||
#include "util/Yaml.h"
|
#include "util/Yaml.h"
|
||||||
|
|
||||||
|
@ -126,7 +127,11 @@ 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 (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->setText("F - pick up " + item->getName());
|
||||||
mPickupInstruction->setPosition(
|
mPickupInstruction->setPosition(
|
||||||
mWindow.getSize().x / 2 - mPickupInstruction->getSize().x / 2,
|
mWindow.getSize().x / 2 - mPickupInstruction->getSize().x / 2,
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Thor/Vectors.hpp>
|
#include <Thor/Vectors.hpp>
|
||||||
|
|
||||||
|
#include "../items/HealthOrb.h"
|
||||||
#include "../items/Weapon.h"
|
#include "../items/Weapon.h"
|
||||||
#include "../Corpse.h"
|
#include "../Corpse.h"
|
||||||
#include "../../util/Log.h"
|
#include "../../util/Log.h"
|
||||||
|
@ -103,23 +104,29 @@ void
|
||||||
Character::onDeath() {
|
Character::onDeath() {
|
||||||
mWorld.insert(std::shared_ptr<Sprite>(new Corpse(getPosition())));
|
mWorld.insert(std::shared_ptr<Sprite>(new Corpse(getPosition())));
|
||||||
|
|
||||||
switch (rand() % 3) {
|
if (rand() % 2)
|
||||||
case 0:
|
dropItem(std::make_shared<HealthOrb>());
|
||||||
dropItem(mFirstWeapon);
|
else
|
||||||
break;
|
switch (rand() % 3) {
|
||||||
case 1:
|
case 0:
|
||||||
dropItem(mSecondWeapon);
|
// To avoid weapons continuing to fire after drop and pickup.
|
||||||
break;
|
mFirstWeapon->releaseTrigger();
|
||||||
case 2:
|
dropItem(mFirstWeapon);
|
||||||
if (mLeftGadget)
|
break;
|
||||||
dropItem(mLeftGadget);
|
case 1:
|
||||||
else if (mRightGadget)
|
// Same here.
|
||||||
dropItem(mRightGadget);
|
mSecondWeapon->releaseTrigger();
|
||||||
}
|
dropItem(mSecondWeapon);
|
||||||
// To avoid weapons continuing to fire after drop and pickup.
|
break;
|
||||||
mFirstWeapon->releaseTrigger();
|
case 2:
|
||||||
mSecondWeapon->releaseTrigger();
|
if (mLeftGadget)
|
||||||
|
dropItem(mLeftGadget);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (mRightGadget)
|
||||||
|
dropItem(mRightGadget);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
19
src/sprites/items/HealthOrb.cpp
Normal file
19
src/sprites/items/HealthOrb.cpp
Normal 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";
|
||||||
|
}
|
||||||
|
|
22
src/sprites/items/HealthOrb.h
Normal file
22
src/sprites/items/HealthOrb.h
Normal 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_ */
|
Reference in a new issue