Only pick up health orb if less than full health.

This commit is contained in:
Felix Ableitner 2013-09-17 19:10:04 +02:00
parent 14749cb378
commit 98090978ce
3 changed files with 16 additions and 10 deletions

View file

@ -169,7 +169,7 @@ Game::updateGui() {
auto item = mWorld.getClosestItem(mPlayer->getPosition()); auto item = mWorld.getClosestItem(mPlayer->getPosition());
auto orb = std::dynamic_pointer_cast<HealthOrb>(item); auto orb = std::dynamic_pointer_cast<HealthOrb>(item);
if (orb) { if (orb && mPlayer->getHealth() < mPlayer->getMaxHealth()) {
mPlayer->onDamage(- orb->getAmountHealed()); mPlayer->onDamage(- orb->getAmountHealed());
mWorld.remove(item); mWorld.remove(item);
} }

View file

@ -27,7 +27,7 @@ Character::Character(const Vector2f& position, Category category,
mWorld(world), mWorld(world),
mPathfinder(pathfinder), mPathfinder(pathfinder),
mMaxHealth(config.get("health", 100)), mMaxHealth(config.get("health", 100)),
mCurrentHealth(mMaxHealth), mHealth(mMaxHealth),
mMovementSpeed(config.get("speed", 0.0f)), mMovementSpeed(config.get("speed", 0.0f)),
mActiveWeapon(mFirstWeapon), mActiveWeapon(mFirstWeapon),
mLastPosition(getPosition()), mLastPosition(getPosition()),
@ -50,15 +50,15 @@ Character::~Character() {
void void
Character::onDamage(int damage) { Character::onDamage(int damage) {
// Otherwise player might not respawn after death // Otherwise player might not respawn after death
if (mCurrentHealth <= 0) if (mHealth <= 0)
return; return;
mCurrentHealth -= damage; mHealth -= damage;
if (mCurrentHealth > mMaxHealth) if (mHealth > mMaxHealth)
mCurrentHealth = mMaxHealth; mHealth = mMaxHealth;
if (mCurrentHealth <= 0) { if (mHealth <= 0) {
onDeath(); onDeath();
setDelete(true); setDelete(true);
} }
@ -72,7 +72,7 @@ Character::onDamage(int damage) {
*/ */
void void
Character::onThink(int elapsed) { Character::onThink(int elapsed) {
if (mCurrentHealth <= 0) if (mHealth <= 0)
return; return;
mActiveWeapon->onThink(elapsed); mActiveWeapon->onThink(elapsed);
@ -256,7 +256,12 @@ Character::selectSecondWeapon() {
*/ */
int int
Character::getHealth() const { Character::getHealth() const {
return mCurrentHealth; return mHealth;
}
int
Character::getMaxHealth() const {
return mMaxHealth;
} }
/** /**

View file

@ -50,6 +50,7 @@ public:
Faction getFaction() const; Faction getFaction() const;
EquippedItems getEquippedItems() const; EquippedItems getEquippedItems() const;
int getHealth() const; int getHealth() const;
int getMaxHealth() const;
int getMagazineAmmo() const; int getMagazineAmmo() const;
int getTotalAmmo() const; int getTotalAmmo() const;
std::string getLeftGadgetName() const; std::string getLeftGadgetName() const;
@ -93,7 +94,7 @@ private:
Pathfinder& mPathfinder; Pathfinder& mPathfinder;
const int mMaxHealth; const int mMaxHealth;
int mCurrentHealth; //< Current health. Between 0 and mMaxHealth. int mHealth; //< Current health. Between 0 and mMaxHealth.
const float mMovementSpeed; const float mMovementSpeed;
std::shared_ptr<Weapon> mFirstWeapon; std::shared_ptr<Weapon> mFirstWeapon;
std::shared_ptr<Weapon> mSecondWeapon; std::shared_ptr<Weapon> mSecondWeapon;