Only pick up health orb if less than full health.
This commit is contained in:
parent
14749cb378
commit
98090978ce
3 changed files with 16 additions and 10 deletions
|
@ -169,7 +169,7 @@ Game::updateGui() {
|
|||
|
||||
auto item = mWorld.getClosestItem(mPlayer->getPosition());
|
||||
auto orb = std::dynamic_pointer_cast<HealthOrb>(item);
|
||||
if (orb) {
|
||||
if (orb && mPlayer->getHealth() < mPlayer->getMaxHealth()) {
|
||||
mPlayer->onDamage(- orb->getAmountHealed());
|
||||
mWorld.remove(item);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Weapon> mFirstWeapon;
|
||||
std::shared_ptr<Weapon> mSecondWeapon;
|
||||
|
|
Reference in a new issue