-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhud.cpp
166 lines (124 loc) · 3.48 KB
/
hud.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "hud.h"
void drawScore(){
glPushMatrix();
int i, len;
char label[] = "Score: ";
void *font = GLUT_STROKE_ROMAN;
glTranslatef(82, 90, 0);
glScalef(0.15, 0.15, 0.15);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glRotatef(180.0,1.0,0.0,0.0);
glScalef(0.125,0.125,0.125);
glTranslatef(-550.0, 100, 0);
len = (int) strlen(label);
for(i = 0;i<len;i++)
glutStrokeCharacter(font, label[i]);
std::ostringstream printNum;
std::string printy;
printNum << GLOBAL.score;
printy = printNum.str();
len = (int) strlen(&printy[0]);
for(i = 0;i<len;i++)
glutStrokeCharacter(font,printy[i]);
printNum.str("");
glPopMatrix();
glPopMatrix();
}
void drawCooldownBar(Tank tank){
glPushMatrix();
int i, len;
char label[] = "Cooldown";
void *font = GLUT_STROKE_ROMAN;
glTranslatef(82, 90, 0);
glScalef(0.15, 0.15, 0.15);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glRotatef(180.0,1.0,0.0,0.0);
glScalef(0.125,0.125,0.125);
glTranslatef(-550.0, -100, 0);
len = (int) strlen(label);
for(i = 0;i<len;i++)
glutStrokeCharacter(font, label[i]);
glPopMatrix();
glBegin(GL_POLYGON);
//draw remaining cooldown time
glColor3ub(255,255,255);
glVertex2f(0.0,0.0);
glVertex2f(0.0,20.0);
glVertex2f((float) (tank.cooldown/100.0)*100.0, 20.0);
glVertex2f((float) (tank.cooldown/100.0)*100.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
//draw missing cooldown time
glColor3ub(0,0,200);
glVertex2f((float) (tank.cooldown/100.0)*100.0, 0.0);
glVertex2f((float) (tank.cooldown/100.0)*100.0, 20.0);
glVertex2f(100.0,20.0);
glVertex2f(100.0,0.0);
glEnd();
glPopMatrix();
}
void drawHealthBar(Tank tank){
glPushMatrix();
int i, len;
char healthLabel[] = "Health";
void *font = GLUT_STROKE_ROMAN;
glTranslatef(82, 95, 0);
glScalef(0.15, 0.15, 0.15);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glRotatef(180.0,1.0,0.0,0.0);
glScalef(0.125,0.125,0.125);
glTranslatef(-400, -130, 0);
len = (int) strlen(healthLabel);
for(i = 0;i<len;i++)
glutStrokeCharacter(font, healthLabel[i]);
glPopMatrix();
glBegin(GL_POLYGON);
//draw remaining health
glColor3ub(0,255,0);
glVertex2f(0.0,0.0);
glVertex2f(0.0,20.0);
glVertex2f((float) (tank.health/100.0)*100.0, 20.0);
glVertex2f((float) (tank.health/100.0)*100.0, 0.0);
glEnd();
glBegin(GL_POLYGON);
//draw missing heath bar
glColor3ub(255,0,0);
glVertex2f((float) (tank.health/100.0)*100.0, 0.0);
glVertex2f((float) (tank.health/100.0)*100.0, 20.0);
glVertex2f(100.0,20.0);
glVertex2f(100.0,0.0);
glEnd();
glPopMatrix();
}
void showFPS(float &fps, int &oldTime, float &actualfps) {
int currentTime = glutGet(GLUT_ELAPSED_TIME);
char str_fps[15];
if ( (currentTime - oldTime) > 1000 ){
actualfps = fps;
fps = 0.0;
oldTime = currentTime;
} else
fps++;
sprintf(&str_fps[0], "FPS = %.0f",actualfps);
glPushMatrix();
glClear(GL_DEPTH_BUFFER_BIT);
void *font = GLUT_STROKE_ROMAN;
glColor3f(1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset the projection style
gluOrtho2D(0.0,100.0,100.0,0.0); // simple ortho
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(01, 03, 0);
glScalef(0.15, 0.15, 0.15);
glRotatef(180.0, 1.0, 0.0, 0.0);
glScalef(0.055,0.055,0.055);
int len = (int) strlen(str_fps);
for (int i = 0; i < len; i++) {
glutStrokeCharacter(font, str_fps[i]);
}
glPopMatrix();
}