From 98090978cea29a106391742f65a5d0d0477b1468 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 17 Sep 2013 19:10:04 +0200 Subject: [PATCH] Only pick up health orb if less than full health. --- src/Game.cpp | 2 +- src/sprites/abstract/Character.cpp | 21 +++++++++++++-------- src/sprites/abstract/Character.h | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Game.cpp b/src/Game.cpp index 3e2a852..4e37772 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -169,7 +169,7 @@ Game::updateGui() { auto item = mWorld.getClosestItem(mPlayer->getPosition()); auto orb = std::dynamic_pointer_cast(item); - if (orb) { + if (orb && mPlayer->getHealth() < mPlayer->getMaxHealth()) { mPlayer->onDamage(- orb->getAmountHealed()); mWorld.remove(item); } diff --git a/src/sprites/abstract/Character.cpp b/src/sprites/abstract/Character.cpp index 1ed8fb0..65a5dea 100644 --- a/src/sprites/abstract/Character.cpp +++ b/src/sprites/abstract/Character.cpp @@ -27,7 +27,7 @@ Character::Character(const Vector2f& position, Category category, mWorld(world), mPathfinder(pathfinder), mMaxHealth(config.get("health", 100)), - mCurrentHealth(mMaxHealth), + mHealth(mMaxHealth), mMovementSpeed(config.get("speed", 0.0f)), mActiveWeapon(mFirstWeapon), mLastPosition(getPosition()), @@ -50,15 +50,15 @@ Character::~Character() { void Character::onDamage(int damage) { // Otherwise player might not respawn after death - if (mCurrentHealth <= 0) + if (mHealth <= 0) return; - mCurrentHealth -= damage; + mHealth -= damage; - if (mCurrentHealth > mMaxHealth) - mCurrentHealth = mMaxHealth; + if (mHealth > mMaxHealth) + mHealth = mMaxHealth; - if (mCurrentHealth <= 0) { + if (mHealth <= 0) { onDeath(); setDelete(true); } @@ -72,7 +72,7 @@ Character::onDamage(int damage) { */ void Character::onThink(int elapsed) { - if (mCurrentHealth <= 0) + if (mHealth <= 0) return; mActiveWeapon->onThink(elapsed); @@ -256,7 +256,12 @@ Character::selectSecondWeapon() { */ int Character::getHealth() const { - return mCurrentHealth; + return mHealth; +} + +int +Character::getMaxHealth() const { + return mMaxHealth; } /** diff --git a/src/sprites/abstract/Character.h b/src/sprites/abstract/Character.h index 3ce29bd..f598050 100644 --- a/src/sprites/abstract/Character.h +++ b/src/sprites/abstract/Character.h @@ -50,6 +50,7 @@ public: Faction getFaction() const; EquippedItems getEquippedItems() const; int getHealth() const; + int getMaxHealth() const; int getMagazineAmmo() const; int getTotalAmmo() const; std::string getLeftGadgetName() const; @@ -93,7 +94,7 @@ private: Pathfinder& mPathfinder; const int mMaxHealth; - int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. + int mHealth; //< Current health. Between 0 and mMaxHealth. const float mMovementSpeed; std::shared_ptr mFirstWeapon; std::shared_ptr mSecondWeapon;