HealthBar Library

Committer:
ll14c4p
Date:
Thu May 04 11:50:43 2017 +0000
Revision:
3:824c16fb35e7
Parent:
1:9f2d307b3b99
Changed == to <= in case of 1 going to -1 without ==0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ll14c4p 0:aa460a91bd33 1 #include "HealthBar.h"
ll14c4p 0:aa460a91bd33 2
ll14c4p 0:aa460a91bd33 3 HealthBar::HealthBar()
ll14c4p 0:aa460a91bd33 4 {
ll14c4p 0:aa460a91bd33 5
ll14c4p 0:aa460a91bd33 6 }
ll14c4p 0:aa460a91bd33 7
ll14c4p 0:aa460a91bd33 8 HealthBar::~HealthBar()
ll14c4p 0:aa460a91bd33 9 {
ll14c4p 0:aa460a91bd33 10
ll14c4p 0:aa460a91bd33 11 }
ll14c4p 0:aa460a91bd33 12
ll14c4p 0:aa460a91bd33 13
ll14c4p 0:aa460a91bd33 14
ll14c4p 0:aa460a91bd33 15 void HealthBar::init(int HP)
ll14c4p 0:aa460a91bd33 16 {
ll14c4p 0:aa460a91bd33 17 _HP = HP;
ll14c4p 0:aa460a91bd33 18
ll14c4p 0:aa460a91bd33 19 }
ll14c4p 0:aa460a91bd33 20
ll14c4p 0:aa460a91bd33 21 void HealthBar::MinusHP1(int HPLost1)
ll14c4p 0:aa460a91bd33 22 {
ll14c4p 0:aa460a91bd33 23 _HPLost1 = HPLost1;
ll14c4p 0:aa460a91bd33 24 }
ll14c4p 0:aa460a91bd33 25
ll14c4p 0:aa460a91bd33 26 void HealthBar::MinusHP2(int HPLost2)
ll14c4p 0:aa460a91bd33 27 {
ll14c4p 0:aa460a91bd33 28 _HPLost2 = HPLost2;
ll14c4p 0:aa460a91bd33 29 }
ll14c4p 0:aa460a91bd33 30
ll14c4p 0:aa460a91bd33 31 void HealthBar::draw(N5110 &lcd)
ll14c4p 0:aa460a91bd33 32 { //printf("%d hp \n", _HP); //working
ll14c4p 0:aa460a91bd33 33 //printf("%d hplost1 \n", _HPLost1); //Working
ll14c4p 1:9f2d307b3b99 34 //printf("%d hplost2 \n", _HPLost2);
ll14c4p 1:9f2d307b3b99 35
ll14c4p 1:9f2d307b3b99 36
ll14c4p 1:9f2d307b3b99 37 //Calculates Total HP by taking the initial HP value and subtracting the
ll14c4p 1:9f2d307b3b99 38 //HP lost variables which update each time an instance resulting in
ll14c4p 1:9f2d307b3b99 39 //HP loss occurs.
ll14c4p 1:9f2d307b3b99 40 //HP Bar actively updates on screen depending on remaining HP.
ll14c4p 1:9f2d307b3b99 41 //When total hp is equal to zero, a variable is assigned the 1 value
ll14c4p 1:9f2d307b3b99 42 //which will cause the player to lose the game.
ll14c4p 1:9f2d307b3b99 43
ll14c4p 0:aa460a91bd33 44 TotalHP = _HP + _HPLost1 + _HPLost2;
ll14c4p 0:aa460a91bd33 45 //printf("%d TotalHP \n", TotalHP);
ll14c4p 0:aa460a91bd33 46 if(TotalHP == 8){
ll14c4p 0:aa460a91bd33 47 lcd.drawLine(0,47,84,47,1); //Working
ll14c4p 0:aa460a91bd33 48 }
ll14c4p 0:aa460a91bd33 49 if(TotalHP == 7){
ll14c4p 0:aa460a91bd33 50 lcd.drawLine(0,47,70,47,1); //Working
ll14c4p 0:aa460a91bd33 51 }
ll14c4p 0:aa460a91bd33 52 if(TotalHP == 6){
ll14c4p 0:aa460a91bd33 53 lcd.drawLine(0,47,60,47,1); //Working
ll14c4p 0:aa460a91bd33 54 }
ll14c4p 0:aa460a91bd33 55 if(TotalHP == 5){
ll14c4p 0:aa460a91bd33 56 lcd.drawLine(0,47,50,47,1); //Working
ll14c4p 0:aa460a91bd33 57 }
ll14c4p 0:aa460a91bd33 58 if(TotalHP == 4){
ll14c4p 0:aa460a91bd33 59 lcd.drawLine(0,47,40,47,1); //Working
ll14c4p 0:aa460a91bd33 60 }
ll14c4p 0:aa460a91bd33 61 if(TotalHP == 3){
ll14c4p 0:aa460a91bd33 62 lcd.drawLine(0,47,30,47,1); //Working
ll14c4p 0:aa460a91bd33 63 }
ll14c4p 0:aa460a91bd33 64 if(TotalHP == 2){
ll14c4p 0:aa460a91bd33 65 lcd.drawLine(0,47,20,47,1); //Working
ll14c4p 0:aa460a91bd33 66 }
ll14c4p 0:aa460a91bd33 67 if(TotalHP == 1){
ll14c4p 0:aa460a91bd33 68 lcd.drawLine(0,47,10,47,1); //Working
ll14c4p 0:aa460a91bd33 69 }
ll14c4p 3:824c16fb35e7 70 if(TotalHP <= 0){
ll14c4p 1:9f2d307b3b99 71 ZeroHP = 1;
ll14c4p 0:aa460a91bd33 72 }
ll14c4p 0:aa460a91bd33 73
ll14c4p 0:aa460a91bd33 74
ll14c4p 0:aa460a91bd33 75 }
ll14c4p 0:aa460a91bd33 76
ll14c4p 1:9f2d307b3b99 77 void HealthBar::update() //To actively update the health bar.
ll14c4p 0:aa460a91bd33 78 {
ll14c4p 0:aa460a91bd33 79 }