diff --git a/source/Game.cpp b/source/Game.cpp index d610cf1..7ed549f 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -33,6 +33,8 @@ Game::Game(tgui::Window& window) : mGenerator.getPlayerSpawn())); mWorld.insertCharacter(mPlayer); + mHealth = window.add(); + mHealth->setTextSize(20); mAmmo = window.add(); mAmmo->setTextSize(20); mCurrentWeapon = window.add(); @@ -85,9 +87,11 @@ Game::updateGui() { if (total < 100) totalString = "0" + totalString; if (total < 10) totalString = "0" + totalString; + mHealth->setText(tgui::to_string(mPlayer->getHealth())); mAmmo->setText(magString + "/" + totalString); mCurrentWeapon->setText(mPlayer->getWeaponName()); + mHealth->setPosition(0, mWindow.getSize().y - mHealth->getSize().y); mAmmo->setPosition(mWindow.getSize().x - mAmmo->getSize().x, mWindow.getSize().y - mAmmo->getSize().y); mCurrentWeapon->setPosition(mWindow.getSize().x - mCurrentWeapon->getSize().x, diff --git a/source/Game.h b/source/Game.h index 794d259..9d12688 100644 --- a/source/Game.h +++ b/source/Game.h @@ -45,6 +45,7 @@ private: tgui::Window& mWindow; sf::Clock mClock; sf::View mWorldView; + tgui::Label* mHealth; tgui::Label* mAmmo; tgui::Label* mCurrentWeapon; diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index c159e31..418c319 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -211,3 +211,7 @@ Character::selectSecondWeapon() { mActiveWeapon->cancelReload(); mActiveWeapon = mSecondWeapon; } +int +Character::getHealth() const { + return mCurrentHealth; +} diff --git a/source/abstract/Character.h b/source/abstract/Character.h index 2f1c354..bebba2a 100644 --- a/source/abstract/Character.h +++ b/source/abstract/Character.h @@ -54,6 +54,7 @@ protected: void toggleWeapon(); void selectFirstWeapon(); void selectSecondWeapon(); + int getHealth() const; private: void move(); diff --git a/source/sprites/Player.h b/source/sprites/Player.h index efbb2c1..14cf0eb 100644 --- a/source/sprites/Player.h +++ b/source/sprites/Player.h @@ -43,6 +43,7 @@ public: using Character::toggleWeapon; using Character::selectFirstWeapon; using Character::selectSecondWeapon; + using Character::getHealth; private: void onThink(int elapsed) override;