Skip to content

Commit

Permalink
episode 15 - the hud - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Limeoats committed Oct 8, 2015
1 parent 6a86723 commit 4dad66a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
48 changes: 48 additions & 0 deletions notes/episode 15 - the HUD - part 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
=====================================================
Remaking Cavestory in C++
Episode 15 - The HUD - Part 2
By: Limeoats
Website: www.limeoats.com
Twitter: @Limeoats
Github: https://github.com/Limeoats/cavestory-development
Reddit: http://www.reddit.com/r/Limeoats
=====================================================


=====================================================
Problem
=====================================================
-We need to finish up the HUD
-Exp bar
-Exp number
-Some gun information
-The "current" health bar



=====================================================
Details
======================================================
currentHealthBar = 0, 25, 39, 5, 83, 72
lvWord = 81, 81, 11, 7, 38, 55
lvNumber = 0, 56, 8, 8, 66, 52
expBar = 0, 72, 40, 8, 83, 52
slash = 72, 48, 8, 8, 100, 36
dashes = 81, 51, 15, 11, 132, 26


=====================================================
Solution
=====================================================
-Fix FPS
-Implement setSourceRectW and setSourceRectH in Sprite
-Add all of the sprites in the correct positions!



=====================================================
Next time
=====================================================
-Build the next map (I'll do it separately, you'll take my .tmx file or do it on your own)
-Get through the door!

13 changes: 12 additions & 1 deletion source/headers/hud.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef HUD_Hf
#ifndef HUD_H
#define HUD_H

#include "sprite.h"
Expand All @@ -16,8 +16,19 @@ class HUD {
private:
Player _player;

//Health sprites
Sprite _healthBarSprite;
Sprite _healthNumber1;
Sprite _currentHealthBar;

//Exp sprites
Sprite _lvWord;
Sprite _lvNumber;
Sprite _expBar;

//Weapon info
Sprite _slash;
Sprite _dashes;
};

#endif
2 changes: 2 additions & 0 deletions source/headers/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Sprite {

void setSourceRectX(int value);
void setSourceRectY(int value);
void setSourceRectW(int value);
void setSourceRectH(int value);

protected:
SDL_Rect _sourceRect;
Expand Down
2 changes: 1 addition & 1 deletion source/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace {
const int FPS = 50;
const int MAX_FRAME_TIME = 5 * 1000 / FPS;
const int MAX_FRAME_TIME = 1000 / FPS;
}

Game::Game() {
Expand Down
17 changes: 17 additions & 0 deletions source/src/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ HUD::HUD(Graphics &graphics, Player &player) {
this->_player = player;
this->_healthBarSprite = Sprite(graphics, "content/sprites/TextBox.png", 0, 40, 64, 8, 35, 70);
this->_healthNumber1 = Sprite(graphics, "content/sprites/TextBox.png", 0, 56, 8, 8, 66, 70);
this->_currentHealthBar = Sprite(graphics, "content/sprites/TextBox.png", 0, 25, 39, 5, 83, 72);
this->_lvWord = Sprite(graphics, "content/sprites/TextBox.png", 81, 81, 11, 7, 38, 55);
this->_lvNumber = Sprite(graphics, "content/sprites/TextBox.png", 0, 56, 8, 8, 66, 52);
this->_expBar = Sprite(graphics, "content/sprites/TextBox.png", 0, 72, 40, 8, 83, 52);
this->_slash = Sprite(graphics, "content/sprites/TextBox.png", 72, 48, 8, 8, 100, 36);
this->_dashes = Sprite(graphics, "content/sprites/TextBox.png", 81, 51, 15, 11, 132, 26);
}

void HUD::update(int elapsedTime) {
this->_healthNumber1.setSourceRectX(8 * this->_player.getCurrentHealth());

//Calculate the width of the health bar
//100% = 39 px
float num = (float)this->_player.getCurrentHealth() / this->_player.getMaxHealth();
this->_currentHealthBar.setSourceRectW(std::floor(num * 39));
}

void HUD::draw(Graphics &graphics) {
this->_healthBarSprite.draw(graphics, this->_healthBarSprite.getX(), this->_healthBarSprite.getY());
this->_healthNumber1.draw(graphics, this->_healthNumber1.getX(), this->_healthNumber1.getY());
this->_currentHealthBar.draw(graphics, this->_currentHealthBar.getX(), this->_currentHealthBar.getY());
this->_lvWord.draw(graphics, this->_lvWord.getX(), this->_lvWord.getY());
this->_lvNumber.draw(graphics, this->_lvNumber.getX(), this->_lvNumber.getY());
this->_expBar.draw(graphics, this->_expBar.getX(), this->_expBar.getY());
this->_slash.draw(graphics, this->_slash.getX(), this->_slash.getY());
this->_dashes.draw(graphics, this->_dashes.getX(), this->_dashes.getY());
}
8 changes: 8 additions & 0 deletions source/src/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ void Sprite::setSourceRectX(int value) {
void Sprite::setSourceRectY(int value) {
this->_sourceRect.y = value;
}

void Sprite::setSourceRectW(int value) {
this->_sourceRect.w = value;
}

void Sprite::setSourceRectH(int value) {
this->_sourceRect.h = value;
}

0 comments on commit 4dad66a

Please sign in to comment.