-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealthbar.cpp
78 lines (68 loc) · 2.48 KB
/
healthbar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "healthbar.h"
#define HEALTH_BAR_DRAWN_WIDTH 77.0
#define HEALTH_BAR_DRAWN_HEIGHT 154.0
#define HEALTH_BAR_TOTAL_WIDTH 128.0
#define HEALTH_BAR_TOTAL_HEIGHT 256.0
HealthBar::HealthBar()
:Draggable( Point( 0, HEALTH_BAR_DRAWN_HEIGHT ),
Point( HEALTH_BAR_DRAWN_WIDTH, 0 ) )
{
totalWidth = 0.0;
totalHeight = 0.0;
drawnWidth = 0.0;
drawnHeight = 0.0;
locked = true;
resourceMgr = ResourceMgr::getInstance();
}
HealthBar::~HealthBar()
{
resourceMgr->release();
}
void HealthBar::unLock()
{
locked = false;
}
void HealthBar::lock()
{
locked = true;
}
void HealthBar::update()
{
if( !locked )
Draggable::update();
}
void HealthBar::draw( double healthPercentage )
{
double textureHeight = HEALTH_BAR_DRAWN_HEIGHT * healthPercentage / 100.0;
double textureRightPerentage = HEALTH_BAR_DRAWN_WIDTH / HEALTH_BAR_TOTAL_WIDTH;
double textureLeft = 0.0;
double textureRight = textureRightPerentage;
double windowCenterX = ( ( window->rightCoord() - window->leftCoord() ) / 2 ) +
window->leftCoord();
double healthBarX = window->leftCoord() + upperLeft.getX();
if( healthBarX >= windowCenterX )
{
textureLeft = textureRightPerentage;
textureRight = 0.0;
}
resourceMgr->drawImage( "healthBarBw" ,
window->leftCoord() + upperLeft.getX(),
window->leftCoord() + upperLeft.getX() + HEALTH_BAR_DRAWN_WIDTH,
window->bottomCoord() + lowerRight.getY(),
window->bottomCoord() + lowerRight.getY() + HEALTH_BAR_DRAWN_HEIGHT,
textureLeft,
textureRight,
( HEALTH_BAR_TOTAL_HEIGHT - HEALTH_BAR_DRAWN_HEIGHT ) / ( HEALTH_BAR_TOTAL_HEIGHT ),
1.0 );
resourceMgr->drawImage( "healthBar" ,
window->leftCoord() + upperLeft.getX(),
window->leftCoord() + upperLeft.getX() + HEALTH_BAR_DRAWN_WIDTH,
window->bottomCoord() + lowerRight.getY(),
window->bottomCoord() + lowerRight.getY() + textureHeight,
textureLeft,
textureRight,
( HEALTH_BAR_TOTAL_HEIGHT - textureHeight ) / ( HEALTH_BAR_TOTAL_HEIGHT ),
1.0 );
if( !locked )
Clickable::draw();
}