[Add] Added basic player health system.
This commit is contained in:
parent
ecfe8abed5
commit
4990e2e1a5
@ -44,6 +44,14 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
||||
_playerXY.SetXY(10, 50);
|
||||
_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;
|
||||
_npcHealth.SetXY(10, 100);
|
||||
_npcHealth.SetTextBlended("NPC Health - XX", vsmall, COLOUR_BLACK);
|
||||
|
||||
_gameRunning = true;
|
||||
while(_gameRunning) {
|
||||
updateTimer.Start();
|
||||
@ -79,6 +87,14 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
|
||||
playerXYString.str("");
|
||||
playerXYString << "Player coords: x" << _player->GetX() << ", y" << _player->GetY();
|
||||
_playerXY.SetTextBlended(playerXYString.str(), vsmall, COLOUR_BLACK);
|
||||
|
||||
playerHealth.str("");
|
||||
playerHealth << "Player Health: " << _player->GetHealth();
|
||||
_playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_BLACK);
|
||||
|
||||
npcHealth.str("");
|
||||
npcHealth << "NPC Health: " << _npc->GetHealth();
|
||||
_npcHealth.SetTextBlended(npcHealth.str(), vsmall, COLOUR_BLACK);
|
||||
}
|
||||
}
|
||||
// Restrict the fps.
|
||||
@ -157,6 +173,8 @@ void Game::Render(void) {
|
||||
_gameRenderTime.RenderLiteral();
|
||||
_gameUpdateTime.RenderLiteral();
|
||||
_playerXY.RenderLiteral();
|
||||
_playerHealth.RenderLiteral();
|
||||
_npcHealth.RenderLiteral();
|
||||
}
|
||||
} else {
|
||||
_ingameMenu.Render();
|
||||
|
@ -50,6 +50,8 @@ private:
|
||||
Text _gameUpdateTime;
|
||||
Text _gameRenderTime;
|
||||
Text _playerXY;
|
||||
Text _playerHealth;
|
||||
Text _npcHealth;
|
||||
|
||||
IngameMenu _ingameMenu;
|
||||
Map _map;
|
||||
|
@ -59,7 +59,6 @@ void Player::Update(void) {
|
||||
Move();
|
||||
AddSpeachBubble("Woot, My name is Allanis, welcome to my home");
|
||||
|
||||
|
||||
// For now The camera will be static.
|
||||
//SetCamera();
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ void Character::Move(void) {
|
||||
if((x < 0) || (x + w) > levelWidth || (x + w) > SCREEN_WIDTH) x -= xVel;
|
||||
if(CheckTileCollisions()) x -= xVel;
|
||||
if(CheckEntityCollisions()) x -= xVel;
|
||||
if(CheckCharacterCollisions()) x -= xVel;
|
||||
//if(CheckCharacterCollisions()) x -= xVel;
|
||||
|
||||
y += yVel;
|
||||
tileX = ((x + (w / 2)) / TILE_WIDTH);
|
||||
|
@ -13,12 +13,18 @@ NPC::~NPC(void) {
|
||||
}
|
||||
|
||||
void NPC::Update(void) {
|
||||
// Store the NPC's health.
|
||||
int health = GetHealth();
|
||||
|
||||
Move();
|
||||
|
||||
if(xVel > 0) directionFacing = FACING_RIGHT;
|
||||
else if(xVel < 0) directionFacing = FACING_LEFT;
|
||||
else if(yVel > 0) directionFacing = FACING_DOWN;
|
||||
else if(yVel < 0) directionFacing = FACING_UP;
|
||||
|
||||
// Deduct health when collision with player is detected.
|
||||
if(CheckCharacterCollisions()) { health -= 1, SetHealth(health); }
|
||||
}
|
||||
|
||||
void NPC::Move(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user