From 19dcda6b8c50a57748b4977be58264d22761e037 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 6 Jul 2013 14:37:16 +0200 Subject: [PATCH] Added health widget to GUI. --- source/Game.cpp | 4 ++++ source/Game.h | 1 + source/abstract/Character.cpp | 4 ++++ source/abstract/Character.h | 1 + source/sprites/Player.h | 1 + 5 files changed, 11 insertions(+) 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;