Added health widget to GUI.
This commit is contained in:
parent
9d133392bc
commit
19dcda6b8c
5 changed files with 11 additions and 0 deletions
|
@ -33,6 +33,8 @@ Game::Game(tgui::Window& window) :
|
|||
mGenerator.getPlayerSpawn()));
|
||||
mWorld.insertCharacter(mPlayer);
|
||||
|
||||
mHealth = window.add<tgui::Label>();
|
||||
mHealth->setTextSize(20);
|
||||
mAmmo = window.add<tgui::Label>();
|
||||
mAmmo->setTextSize(20);
|
||||
mCurrentWeapon = window.add<tgui::Label>();
|
||||
|
@ -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,
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
tgui::Window& mWindow;
|
||||
sf::Clock mClock;
|
||||
sf::View mWorldView;
|
||||
tgui::Label* mHealth;
|
||||
tgui::Label* mAmmo;
|
||||
tgui::Label* mCurrentWeapon;
|
||||
|
||||
|
|
|
@ -211,3 +211,7 @@ Character::selectSecondWeapon() {
|
|||
mActiveWeapon->cancelReload();
|
||||
mActiveWeapon = mSecondWeapon;
|
||||
}
|
||||
int
|
||||
Character::getHealth() const {
|
||||
return mCurrentHealth;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ protected:
|
|||
void toggleWeapon();
|
||||
void selectFirstWeapon();
|
||||
void selectSecondWeapon();
|
||||
int getHealth() const;
|
||||
|
||||
private:
|
||||
void move();
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
using Character::toggleWeapon;
|
||||
using Character::selectFirstWeapon;
|
||||
using Character::selectSecondWeapon;
|
||||
using Character::getHealth;
|
||||
|
||||
private:
|
||||
void onThink(int elapsed) override;
|
||||
|
|
Reference in a new issue