[Add] Health bar for player.
This commit is contained in:
parent
4ee9354769
commit
e565fb7007
@ -34,24 +34,32 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
|||||||
Timer renderTimer;
|
Timer renderTimer;
|
||||||
Timer updateTimer;
|
Timer updateTimer;
|
||||||
|
|
||||||
_gameRenderTime.SetXY(10, 10);
|
_gameRenderTime.SetXY(10, 50);
|
||||||
_gameRenderTime.SetTextBlended("Render - XX", vsmall, COLOUR_BLACK);
|
_gameRenderTime.SetTextBlended("Render - XX", vsmall, COLOUR_BLACK);
|
||||||
|
|
||||||
_gameUpdateTime.SetXY(10, 30);
|
_gameUpdateTime.SetXY(10, 70);
|
||||||
_gameUpdateTime.SetTextBlended("Update - XX", vsmall, COLOUR_BLACK);
|
_gameUpdateTime.SetTextBlended("Update - XX", vsmall, COLOUR_BLACK);
|
||||||
|
|
||||||
stringstream playerXYString;
|
stringstream playerXYString;
|
||||||
_playerXY.SetXY(10, 50);
|
_playerXY.SetXY(10, 90);
|
||||||
_playerXY.SetTextBlended("Player coords - XX XX", vsmall, COLOUR_BLACK);
|
_playerXY.SetTextBlended("Player coords - XX XX", vsmall, COLOUR_BLACK);
|
||||||
|
|
||||||
stringstream playerHealth;
|
|
||||||
_playerHealth.SetXY(10, 80);
|
|
||||||
_playerHealth.SetTextBlended("Player Health - XX", vsmall, COLOUR_BLACK);
|
|
||||||
|
|
||||||
stringstream npcHealth;
|
stringstream npcHealth;
|
||||||
_npcHealth.SetXY(10, 100);
|
_npcHealth.SetXY(10, 110);
|
||||||
_npcHealth.SetTextBlended("NPC 0 Health - XX", vsmall, COLOUR_BLACK);
|
_npcHealth.SetTextBlended("NPC 0 Health - XX", vsmall, COLOUR_BLACK);
|
||||||
|
|
||||||
|
_healthBarBg.SetRGB(0, 0, 0);
|
||||||
|
_healthBarBg.SetXY(10, 20);
|
||||||
|
_healthBarBg.SetWidthHeight(200, 25);
|
||||||
|
|
||||||
|
_healthBar.SetRGB(255, 0, 0);
|
||||||
|
_healthBar.SetXY(10, 20);
|
||||||
|
_healthBar.SetWidthHeight(200, 25);
|
||||||
|
|
||||||
|
stringstream playerHealth;
|
||||||
|
_playerHealth.SetXY(15, 27);
|
||||||
|
_playerHealth.SetTextBlended("Player Health - XX", vsmall, COLOUR_WHITE);
|
||||||
|
|
||||||
_gameRunning = true;
|
_gameRunning = true;
|
||||||
while(_gameRunning) {
|
while(_gameRunning) {
|
||||||
bool stillRunning = true;
|
bool stillRunning = true;
|
||||||
@ -90,6 +98,14 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
|||||||
fpsCalc.Start();
|
fpsCalc.Start();
|
||||||
frame = 0;
|
frame = 0;
|
||||||
|
|
||||||
|
playerHealth.str("");
|
||||||
|
playerHealth << "Player Health: " << _player->GetHealth();
|
||||||
|
_playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_WHITE);
|
||||||
|
|
||||||
|
_healthBar.SetWidthHeight(
|
||||||
|
(int)(((float)_player->GetHealth() / 100.0f) * 200.0f),
|
||||||
|
_healthBar.GetHeight());
|
||||||
|
|
||||||
// Check to see if we are allowed to display debug info.
|
// Check to see if we are allowed to display debug info.
|
||||||
if(debugEnabled) {
|
if(debugEnabled) {
|
||||||
_gameUpdateTime.SetTextBlended("Update - " + updateTimer.GetTicksStr(), vsmall, COLOUR_BLACK);
|
_gameUpdateTime.SetTextBlended("Update - " + updateTimer.GetTicksStr(), vsmall, COLOUR_BLACK);
|
||||||
@ -99,10 +115,6 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
|||||||
playerXYString << "Player coords: x" << _player->GetX() << ", y" << _player->GetY();
|
playerXYString << "Player coords: x" << _player->GetX() << ", y" << _player->GetY();
|
||||||
_playerXY.SetTextBlended(playerXYString.str(), vsmall, COLOUR_BLACK);
|
_playerXY.SetTextBlended(playerXYString.str(), vsmall, COLOUR_BLACK);
|
||||||
|
|
||||||
playerHealth.str("");
|
|
||||||
playerHealth << "Player Health: " << _player->GetHealth();
|
|
||||||
_playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_BLACK);
|
|
||||||
|
|
||||||
int npc0Health = 0;
|
int npc0Health = 0;
|
||||||
if(_map.GetWorld().GetNPCCount() == 0) {
|
if(_map.GetWorld().GetNPCCount() == 0) {
|
||||||
npc0Health = 0;
|
npc0Health = 0;
|
||||||
@ -139,6 +151,7 @@ void Game::HandleInput(void) {
|
|||||||
_ingameMenu.SetStatus(true);
|
_ingameMenu.SetStatus(true);
|
||||||
if(event.key.keysym.sym == SDLK_p)
|
if(event.key.keysym.sym == SDLK_p)
|
||||||
debugEnabled = !debugEnabled;
|
debugEnabled = !debugEnabled;
|
||||||
|
_player->SetHealth(50);
|
||||||
}
|
}
|
||||||
else if(event.type == SDL_QUIT) {
|
else if(event.type == SDL_QUIT) {
|
||||||
_gameRunning = false;
|
_gameRunning = false;
|
||||||
@ -188,18 +201,22 @@ void Game::UpdateGame(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::Render(void) {
|
void Game::Render(void) {
|
||||||
// SDL_FillRect(screen, NULL, 0); // You might want to clear the buffer! --konom
|
//SDL_FillRect(screen, NULL, 0); // You might want to clear the buffer! --konom
|
||||||
if(_ingameMenu.GetStatus() == false) {
|
if(_ingameMenu.GetStatus() == false) {
|
||||||
_map.Render();
|
_map.Render();
|
||||||
_player->Render();
|
_player->Render();
|
||||||
|
|
||||||
|
_healthBarBg.DrawLiteral();
|
||||||
|
_healthBar.DrawLiteral();
|
||||||
|
_playerHealth.RenderLiteral();
|
||||||
|
|
||||||
if(debugEnabled) {
|
if(debugEnabled) {
|
||||||
_gameRenderTime.RenderLiteral();
|
_gameRenderTime.RenderLiteral();
|
||||||
_gameUpdateTime.RenderLiteral();
|
_gameUpdateTime.RenderLiteral();
|
||||||
_playerXY.RenderLiteral();
|
_playerXY.RenderLiteral();
|
||||||
_playerHealth.RenderLiteral();
|
|
||||||
_npcHealth.RenderLiteral();
|
_npcHealth.RenderLiteral();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_ingameMenu.Render();
|
_ingameMenu.Render();
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "../libUnuk/System/Debug.h"
|
#include "../libUnuk/System/Debug.h"
|
||||||
#include "../libUnuk/UI/Text.h"
|
#include "../libUnuk/UI/Text.h"
|
||||||
#include "../libUnuk/Engine/MemClass.h"
|
#include "../libUnuk/Engine/MemClass.h"
|
||||||
|
#include "../libUnuk/System/Rect.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
enum gameNavVal_t { gameMainMenu, gameQuitGame };
|
enum gameNavVal_t { gameMainMenu, gameQuitGame };
|
||||||
@ -49,11 +50,14 @@ private:
|
|||||||
Text _gameUpdateTime;
|
Text _gameUpdateTime;
|
||||||
Text _gameRenderTime;
|
Text _gameRenderTime;
|
||||||
Text _playerXY;
|
Text _playerXY;
|
||||||
Text _playerHealth;
|
|
||||||
Text _npcHealth;
|
Text _npcHealth;
|
||||||
|
|
||||||
IngameMenu _ingameMenu;
|
IngameMenu _ingameMenu;
|
||||||
Map _map;
|
Map _map;
|
||||||
|
|
||||||
Player* _player;
|
Player* _player;
|
||||||
|
|
||||||
|
Text _playerHealth;
|
||||||
|
Rect _healthBarBg;
|
||||||
|
Rect _healthBar;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user