[Add] Added basic player health system.

This commit is contained in:
Rtch90 2011-12-28 00:56:07 +00:00
parent ecfe8abed5
commit 4990e2e1a5
5 changed files with 27 additions and 2 deletions

View File

@ -44,6 +44,14 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
_playerXY.SetXY(10, 50); _playerXY.SetXY(10, 50);
_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;
_npcHealth.SetXY(10, 100);
_npcHealth.SetTextBlended("NPC Health - XX", vsmall, COLOUR_BLACK);
_gameRunning = true; _gameRunning = true;
while(_gameRunning) { while(_gameRunning) {
updateTimer.Start(); updateTimer.Start();
@ -79,6 +87,14 @@ gameNavVal_t Game::Run(const string savegameIDArg) {
playerXYString.str(""); playerXYString.str("");
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);
npcHealth.str("");
npcHealth << "NPC Health: " << _npc->GetHealth();
_npcHealth.SetTextBlended(npcHealth.str(), vsmall, COLOUR_BLACK);
} }
} }
// Restrict the fps. // Restrict the fps.
@ -157,6 +173,8 @@ void Game::Render(void) {
_gameRenderTime.RenderLiteral(); _gameRenderTime.RenderLiteral();
_gameUpdateTime.RenderLiteral(); _gameUpdateTime.RenderLiteral();
_playerXY.RenderLiteral(); _playerXY.RenderLiteral();
_playerHealth.RenderLiteral();
_npcHealth.RenderLiteral();
} }
} else { } else {
_ingameMenu.Render(); _ingameMenu.Render();

View File

@ -50,6 +50,8 @@ private:
Text _gameUpdateTime; Text _gameUpdateTime;
Text _gameRenderTime; Text _gameRenderTime;
Text _playerXY; Text _playerXY;
Text _playerHealth;
Text _npcHealth;
IngameMenu _ingameMenu; IngameMenu _ingameMenu;
Map _map; Map _map;

View File

@ -59,7 +59,6 @@ void Player::Update(void) {
Move(); Move();
AddSpeachBubble("Woot, My name is Allanis, welcome to my home"); AddSpeachBubble("Woot, My name is Allanis, welcome to my home");
// For now The camera will be static. // For now The camera will be static.
//SetCamera(); //SetCamera();
} }

View File

@ -142,7 +142,7 @@ void Character::Move(void) {
if((x < 0) || (x + w) > levelWidth || (x + w) > SCREEN_WIDTH) x -= xVel; if((x < 0) || (x + w) > levelWidth || (x + w) > SCREEN_WIDTH) x -= xVel;
if(CheckTileCollisions()) x -= xVel; if(CheckTileCollisions()) x -= xVel;
if(CheckEntityCollisions()) x -= xVel; if(CheckEntityCollisions()) x -= xVel;
if(CheckCharacterCollisions()) x -= xVel; //if(CheckCharacterCollisions()) x -= xVel;
y += yVel; y += yVel;
tileX = ((x + (w / 2)) / TILE_WIDTH); tileX = ((x + (w / 2)) / TILE_WIDTH);

View File

@ -13,12 +13,18 @@ NPC::~NPC(void) {
} }
void NPC::Update(void) { void NPC::Update(void) {
// Store the NPC's health.
int health = GetHealth();
Move(); Move();
if(xVel > 0) directionFacing = FACING_RIGHT; if(xVel > 0) directionFacing = FACING_RIGHT;
else if(xVel < 0) directionFacing = FACING_LEFT; else if(xVel < 0) directionFacing = FACING_LEFT;
else if(yVel > 0) directionFacing = FACING_DOWN; else if(yVel > 0) directionFacing = FACING_DOWN;
else if(yVel < 0) directionFacing = FACING_UP; 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) { void NPC::Move(void) {