-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_entity.cpp
282 lines (242 loc) · 7.87 KB
/
cl_entity.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include "mastrix.hpp"
#include <typeinfo>
ClientConsoleVar<bool> showEdgeLengths("show_edge_lengths", false);
CLEntity::CLEntity(
int newID,
std::string newSpriteName,
float drawScale,
Position &newPos,
int type,
int team,
std::string label,
int effect)
{
entID = newID;
spriteName = newSpriteName;
scale = drawScale;
position = newPos;
sprite = images.getImage(newSpriteName.c_str());
entType = type;
entTeam = team;
enginesSet = 0x0;
color = Color(255, 255, 255);
this->label = label;
this->effect = effect;
shieldTime = 0.0;
isAlly = false;
shouldChangeColor = false;
}
CLEntity::~CLEntity()
{
sprite = 0;
}
void CLEntity::setShield(float time, short type, float rad) {
shieldRadius = rad;
shieldTime = time;
shieldType = type;
}
/*
void CLEntity::drawShield() {
int density = 180;
for (int i = 0; i < density; i++) {
float origX = position.getX();
float origY = position.getY();
float dotX = position.getX() + radius*cos(randFloat(0.0, M_PI*2));
float dotY = position.getY() + radius*sin(randFloat(0.0, M_PI*2));
glEnable(GL_POINT_SMOOTH);
graphics.drawPoint(Color(64,64,255),dotX,dotY,10);
glDisable(GL_POINT_SMOOTH);
}
}
*/
void Client::drawWaypointEdges()
{
if (!areEdgesVisible)
return;
for (CLEdgePool::iterator ii = edges.begin(); ii != edges.end(); ++ii)
{
ClientEdge ¤tEdge = (*ii);
if (entpool.find(currentEdge.getEnt1ID()) == entpool.end())
return;
if (entpool.find(currentEdge.getEnt2ID()) == entpool.end())
return;
Position &point1 = entpool[currentEdge.getEnt1ID()]->getPosition();
Position &point2 = entpool[currentEdge.getEnt2ID()]->getPosition();
float point1DrawX = point1.getX();
float point1DrawY = point1.getY();
float point2DrawX = point2.getX();
float point2DrawY = point2.getY();
//now convert these world coordinates into drawing coordinates
convertToDrawCoords(point1DrawX, point1DrawY);
convertToDrawCoords(point2DrawX, point2DrawY);
graphics.drawLine(
Color(255, 0, 0),
point1DrawX,
point1DrawY,
point2DrawX,
point2DrawY);
if (showEdgeLengths)
{
float dist = sqrtf(distSquaredBetween(
Position(point1.getX(), point1.getY()),
Position(point2.getX(), point2.getY())));
int x;
int y;
graphics.drawText(
fcvt(dist, 0, &x, &y),
(point2DrawX + point1DrawX) / 2,
(point2DrawY + point1DrawY) / 2);
}
}
}
void Client::drawMapBorders()
{
static Color borderColor = Color(255, 255, 0);
//need to convert world border coordinates to camera coordinates
float topLeftX = leftBorder;
float topLeftY = topBorder;
float topRightX = rightBorder;
float topRightY = topBorder;
float bottomRightX = rightBorder;
float bottomRightY = bottomBorder;
float bottomLeftX = leftBorder;
float bottomLeftY = bottomBorder;
convertToDrawCoords(topLeftX, topLeftY);
convertToDrawCoords(topRightX, topRightY);
convertToDrawCoords(bottomRightX, bottomRightY);
convertToDrawCoords(bottomLeftX, bottomLeftY);
const float borderWidth = 10.0f;
glColor3f(1, 1, 0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
glVertex2f(topLeftX, topLeftY);
glVertex2f(topRightX, topRightY);
glVertex2f(bottomRightX, bottomRightY);
glVertex2f(bottomLeftX, bottomLeftY);
glEnd();
}
void Client::drawRects()
{
for(unsigned ii=0; ii<rectpool.size(); ii++)
{
float min_x = rectpool[ii].min_x,
max_x = rectpool[ii].max_x,
min_y = rectpool[ii].min_y,
max_y = rectpool[ii].max_y;
convertToDrawCoords(min_x, min_y);
convertToDrawCoords(max_x, max_y);
glColor3f(0.6, 0.6, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(min_x, min_y);
glVertex2f(max_x, min_y);
glVertex2f(max_x, max_y);
glVertex2f(min_x, max_y);
glEnd();
glColor4f(0.6, 0.6, 1.0, 0.3);
glBegin(GL_QUADS);
glVertex2f(min_x, min_y);
glVertex2f(max_x, min_y);
glVertex2f(max_x, max_y);
glVertex2f(min_x, max_y);
glEnd();
graphics.drawText(rectpool[ii].name.c_str(), min_x+2, max_y-2);
}
}
static void drawShot(int level, float x, float y);
void Client::drawEnt(CLEntity *ent)
{
if (!ent->isVisible)
return;
float draw_x = ent->position.getX()*zoom - getCamera().getX()*zoom +
viewport->center_x;
float draw_y = ent->position.getY()*zoom - getCamera().getY()*zoom +
viewport->center_y;
float draw_radius = ent->scale*zoom;
float size = ent->sprite->getWidth() * draw_radius / 2;
if(draw_x+size < 0 || draw_x-size > viewport->right || draw_y+size < 0 || draw_y-size > viewport->bottom)
return;
//if this is a bot, color it if it's about to collide with something
if (ent->shouldChangeColor)
graphics.setColor(ent->color);
else
graphics.setColor(Color(255, 255, 255));
//our new rotation argument automatically converts from radians to degrees
graphics.drawColoredImage(
ent->sprite,
draw_x, draw_y,
ent->position.getR(),
draw_radius);
//draw an icon to show that the bot is allied with the human player
/* if (ent->isAlly)
{
graphics.drawImage(
images.getImage("images/waypoint.png"),
draw_x,
draw_y - 50 * zoom,
0.0f,
0.2f);
}*/
if(ent->enginesSet)
particlePool.engineExhaust(ent->getID(), ent->radius, ent->enginesSet);
switch(ent->effect)
{
case effect_sparking: particlePool.spark(ent->getPosition()); break;
case effect_trail: particlePool.trail(ent->getPosition(), ent->scale*ent->sprite->getWidth()/2); break;
case effect_missile_trail: particlePool.missileTrail(ent->getPosition(), ent->scale*ent->sprite->getWidth()/2); break;
case effect_shot: drawShot(1, draw_x, draw_y); break;
case effect_shot2: drawShot(2, draw_x, draw_y); break;
case effect_shot3: drawShot(3, draw_x, draw_y); break;
case effect_shot4: drawShot(4, draw_x, draw_y); break;
case effect_money: particlePool.moneyTrail(ent->getPosition(), ent->scale*ent->sprite->getWidth()/2); break;
default: break;
}
graphics.drawTextCentered(ent->label.c_str(), draw_x, draw_y+size+10);
if(selectedEntId == ent->entID)
{
Color selectedColor(0, 255, 0);
graphics.drawLine(selectedColor, draw_x-size, draw_y-size, draw_x+size, draw_y-size);
graphics.drawLine(selectedColor, draw_x+size, draw_y-size, draw_x+size, draw_y+size);
graphics.drawLine(selectedColor, draw_x+size, draw_y+size, draw_x-size, draw_y+size);
graphics.drawLine(selectedColor, draw_x-size, draw_y+size, draw_x-size, draw_y-size);
}
}
const float shot_size = 6.5;
static void drawShot(int level, float x, float y)
{
float jitter = 0.7;
glPointSize(11 * zoom);
glEnable(GL_POINT_SMOOTH);
switch(level)
{
default:
case 1:
glBegin(GL_POINTS);
glColor4f(0.0, 1.0, 0.0, 0.6);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glColor4f(0.3, 0.0, 1.0, 0.6);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glColor4f(1.0, 1.0, 1.0, 0.8);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glEnd();
break;
case 2:
glBegin(GL_POINTS);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glColor4f(1.0, 1.0, 0.0, 0.8);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glEnd();
break;
case 3:
jitter = 2.0;
glBegin(GL_POINTS);
glColor4f(1.0, 1.0, 1.0, 1.0);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glColor4f(0.7, 0.7, 1.0, 1.0);
glVertex2f(x+randFloat(-jitter,jitter), y+randFloat(-jitter,jitter));
glEnd();
break;
}
}