Added health widget to GUI.

This commit is contained in:
Felix Ableitner 2013-07-06 14:37:16 +02:00
parent 9d133392bc
commit 19dcda6b8c
5 changed files with 11 additions and 0 deletions

View file

@ -33,6 +33,8 @@ Game::Game(tgui::Window& window) :
mGenerator.getPlayerSpawn())); mGenerator.getPlayerSpawn()));
mWorld.insertCharacter(mPlayer); mWorld.insertCharacter(mPlayer);
mHealth = window.add<tgui::Label>();
mHealth->setTextSize(20);
mAmmo = window.add<tgui::Label>(); mAmmo = window.add<tgui::Label>();
mAmmo->setTextSize(20); mAmmo->setTextSize(20);
mCurrentWeapon = window.add<tgui::Label>(); mCurrentWeapon = window.add<tgui::Label>();
@ -85,9 +87,11 @@ Game::updateGui() {
if (total < 100) totalString = "0" + totalString; if (total < 100) totalString = "0" + totalString;
if (total < 10) totalString = "0" + totalString; if (total < 10) totalString = "0" + totalString;
mHealth->setText(tgui::to_string(mPlayer->getHealth()));
mAmmo->setText(magString + "/" + totalString); mAmmo->setText(magString + "/" + totalString);
mCurrentWeapon->setText(mPlayer->getWeaponName()); mCurrentWeapon->setText(mPlayer->getWeaponName());
mHealth->setPosition(0, mWindow.getSize().y - mHealth->getSize().y);
mAmmo->setPosition(mWindow.getSize().x - mAmmo->getSize().x, mAmmo->setPosition(mWindow.getSize().x - mAmmo->getSize().x,
mWindow.getSize().y - mAmmo->getSize().y); mWindow.getSize().y - mAmmo->getSize().y);
mCurrentWeapon->setPosition(mWindow.getSize().x - mCurrentWeapon->getSize().x, mCurrentWeapon->setPosition(mWindow.getSize().x - mCurrentWeapon->getSize().x,

View file

@ -45,6 +45,7 @@ private:
tgui::Window& mWindow; tgui::Window& mWindow;
sf::Clock mClock; sf::Clock mClock;
sf::View mWorldView; sf::View mWorldView;
tgui::Label* mHealth;
tgui::Label* mAmmo; tgui::Label* mAmmo;
tgui::Label* mCurrentWeapon; tgui::Label* mCurrentWeapon;

View file

@ -211,3 +211,7 @@ Character::selectSecondWeapon() {
mActiveWeapon->cancelReload(); mActiveWeapon->cancelReload();
mActiveWeapon = mSecondWeapon; mActiveWeapon = mSecondWeapon;
} }
int
Character::getHealth() const {
return mCurrentHealth;
}

View file

@ -54,6 +54,7 @@ protected:
void toggleWeapon(); void toggleWeapon();
void selectFirstWeapon(); void selectFirstWeapon();
void selectSecondWeapon(); void selectSecondWeapon();
int getHealth() const;
private: private:
void move(); void move();

View file

@ -43,6 +43,7 @@ public:
using Character::toggleWeapon; using Character::toggleWeapon;
using Character::selectFirstWeapon; using Character::selectFirstWeapon;
using Character::selectSecondWeapon; using Character::selectSecondWeapon;
using Character::getHealth;
private: private:
void onThink(int elapsed) override; void onThink(int elapsed) override;