-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhealth.cpp
More file actions
66 lines (62 loc) · 1.97 KB
/
health.cpp
File metadata and controls
66 lines (62 loc) · 1.97 KB
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
#include "health.h"
Health::Health() :
screen(IOManager::getInstance().getScreen()),
start(Vector2f(20, 20)),
totalLength(180),
currentLength(180),
thick(14),
increments(20),
interval(1000),
deltaTime(0),
RED( SDL_MapRGB(screen->format, 0xff, 0x00, 0x00) ),
GRAY( SDL_MapRGB(screen->format, 0xce, 0xb4, 0xb4) ),
BLACK( SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) ),
color(RED) {
}
Health::Health(int sx, int sy, int tl, int cl,
float t, int inc, Uint32 c, float sp):
screen(IOManager::getInstance().getScreen()),
start(Vector2f(sx, sy)),
totalLength(tl),
currentLength(cl),
thick(t),
increments(inc),
interval(sp),
deltaTime(SDL_GetTicks()),
RED( SDL_MapRGB(screen->format, 0xff, 0x00, 0x00) ),
GRAY( SDL_MapRGB(screen->format, 0xff, 0xff, 0xff) ),
BLACK( SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) ),
color(c) {
}
void Health::drawBox() const {
Draw_AALine(screen, start[0], start[1],
start[0]+totalLength, start[1],
thick, GRAY);
// Two Horizontal lines
Draw_AALine(screen, start[0], start[1]-8,
start[0]+totalLength, start[1]-8,
1.0, BLACK);
Draw_AALine(screen, start[0], start[1]+8,
start[0]+totalLength, start[1]+8,
1.0, BLACK);
// Two Vertical lines
Draw_AALine(screen, start[0]-1, start[1]-8,
start[0]-1, start[1]+8,
2.0, BLACK);
Draw_AALine(screen, start[0]+totalLength+1, start[1]-8,
start[0]+totalLength+1, start[1]+8,
2.0, BLACK);
}
void Health::draw() const {
drawBox();
Draw_AALine(screen, start[0], start[1],
start[0]+currentLength, start[1],
thick, color);
}
void Health::update(Uint32 ticks) {
deltaTime += ticks;
if ( currentLength > 0 && deltaTime > interval ) {
deltaTime = 0;
currentLength -= increments;
}
}