-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglaction.h
605 lines (457 loc) · 13.1 KB
/
glaction.h
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/*
Àâòîð(ñ): Ñàííèêîâ, Êóëåáÿêèí, Ñòóïàê è Ïàðõîìåíêî
Íàçâàíèå êîìàíäû: AGRAGE
e-mail: [email protected]
*/
#if ! defined(_GLACTON_VILLAGE_)
#define _GLACTON_VILLAGE_
#if _MSC_VER > 1000
#pragma once
#endif
#define MAX_HOUSES 8
// ñòðóêòóðà äëÿ ïëàçìåííîé ïóëè
struct sBullet {
GLVECTOR3 pos;
GLVECTOR3 vec;
};
// Ïîëüçîâàòåëü îò ïåðâîãî ëèöà
class xUser {
private:
xSound* snd_uron;
xSound* snd_fire;
xSound* snd_step;
xFigure* gun;
GLuint tex_gun;
GLuint tex_lazer;
GLVECTOR3 pos;
GLVECTOR3 size;
BOOL ifire;
BOOL imove;
int life;
std::list<sBullet> bullets;
public:
xUser(void);
xUser(LPDIRECTSOUND sound);
~xUser();
public:
void Create(LPDIRECTSOUND sound);
void Initialize(void);
void Display(GLfloat felapsed, GLfloat ftime);
void DisplayLazer(GLfloat felapsed, GLfloat ftime, GLfloat angleY);
void DisplayCross(const LPSIZE pscreen);
void OnFire(WPARAM wParam, const LPGLVECTOR3& hpos, GLfloat felapsed, GLfloat yaw, GLfloat pitch);
void SetMove(BOOL move);
void Destroy(void);
void DecLife(void);
std::list<sBullet>* Bullets(void) {
return &bullets;
}
int GetLife(void) const {
return life;
}
GLVECTOR3& Size(void) {
return size;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////
// ñòðóêòóðà äëÿ ðîáîòà "ìàðêè - TM"
struct sRobotTM {
GLVECTOR3 pos;
GLVECTOR3 vec;
GLVECTOR3 rot;
GLfloat angle;
int life;
BOOL uron;
BOOL crush;
GLVECTOR2 cadrs;
GLfloat time_crush;
GLfloat fsmoke;
GLfloat length;
GLfloat position;
GLVECTOR3 tpos[2];
int primary_task;
xSound* snd_uron;
xSound* snd_crush;
xSound* snd_move;
GLfloat time_sound;
static const int MAX_ROBOTS_TM;
sRobotTM(void){}
sRobotTM(const LPGLVECTOR3& user_pos, GLfloat x, GLfloat z) {
this->Initialize(user_pos, x, z);
}
// èíèöèàëèçàöèÿ
void Initialize(const LPGLVECTOR3& user_pos, GLfloat x, GLfloat z) {
pos.x = x;
pos.z = z;
pos.y = 0.0f;
rot = 0.0f;
vec = 0.0f;
life = 10;
angle = 0.0f;
crush = FALSE;
uron = FALSE;
fsmoke = 0.0f;
primary_task = rand() % 2;
position = 0.0f;
length = 0.0f;
time_sound = 0.0f;
if(primary_task != 0) {
VectorSubtract(&vec, &pos, user_pos);
rot.y = fDEGREE(atan2f(vec.x, vec.z));
VectorNormalize(&vec);
vec.y = 0.0f;
vec *= 0.9f;
tpos[0] = pos;
tpos[1] = *user_pos;
tpos[0].y = tpos[1].y = 0.0f;
length = VectorLength(&(tpos[0] - tpos[1]));
}
snd_move->Play(DSBPLAY_LOOPING);
snd_move->SetVolume(DSBVOLUME_MIN);
}
// âñÿêèå ïîëåçíûå äåéñòâèÿ ïî àíèìàöèè-äâèæåíèÿ
void UpdateMove(const LPGLVECTOR3& user_pos, GLfloat cube, GLfloat felapsed, GLfloat ftime) {
if(crush)
return;
if(! primary_task) {
VectorSubtract(&vec, &pos, user_pos);
rot.y = fDEGREE(atan2f(vec.x, vec.z));
VectorNormalize(&vec);
vec.y = 0.0f;
vec *= 0.9f;
pos -= vec * fNUM(felapsed, 21.0f);
} else {
GLfloat tmp = pos.y;
LineP2(&pos, position / length, &tpos[0], &tpos[1]);
position += fNUM(felapsed, 20.0f);
pos.y = tmp;
if(position >= length) {
primary_task = 0;
position = length = 0.0f;
return;
}
// åñëè â ðàäèóñå ïîëüçîâàòåëü îêàæåòñÿ âçÿòü íàïðàâëåíèå íà íåãî
if(IsCollisionSphere(&pos, 25.0f, user_pos, 25.0f))
primary_task = 0;
}
angle -= fNUM(felapsed, 290.0f);
// ÷åðåç êàæäóþ ñåêóíäó ðåãóëèðîâêà ãðìîêñîòè çâêà íà ðàññòîÿíèå ìåæäó ïîëüçîâàòåëåì
if((ftime - time_sound) > 1000.0f) {
time_sound = ftime;
this->volume_ctrl(user_pos);
}
}
// âûâîä äûìà è âçðûâà
void DisplayEffect(const LPGLVECTOR3& user_pos, GLuint tex, GLfloat angleY, GLfloat felapsed, GLfloat ftime) {
GLVECTOR3 vpos;
if(uron) { // îáðàáîòêà óðîíà
xTextura::Set(tex);
fsmoke -= fNUM(felapsed, 1.4f);
xModel::DrawRect(&GLVECTOR3(pos.x, pos.y + 5.5f, pos.z), fRAND(5, 9), angleY);
if(fsmoke < 0.1f)
uron = FALSE;
}
if(crush) { // îáðàáîòêà âçðûâà
const GLfloat cadr = 1.0f / 3.0f;
if((ftime - time_crush) > 70.0f) {
time_crush = ftime;
cadrs.x += cadr;
if(cadrs.x >= 1.0f) {
cadrs.x = 0.0f;
cadrs.y += cadr;
if(cadrs.y >= 1.0f) {
cadrs = 0.0f;
crush = FALSE;
GLfloat rex = -500 + 10.0f;
GLfloat rez = -500 + fRAND(0, (int)500 * 2);
if((rand() % 2) != 0) {
rex = 500 - 10.0f;
rez = -255 + fRAND(1, (int)500);
}
this->Initialize(user_pos, rex, rez);
return;
}
}
}
xTextura::Set(tex);
xModel::DrawAnimationSprite(&GLVECTOR3(pos.x, pos.y + 5.5f, pos.z), &GLVECTOR3(8.0f, 8.0f, 0.0f), angleY, &cadrs, &GLVECTOR2(cadr));
}
}
BOOL IsCrush(void) const {
return crush;
}
BOOL IsUron(void) const {
return uron;
}
// ïðîâåðêà ñòîëêíîâåíèÿ ñ ïîëüçîâàòåëüñêîé ïóëåé
int IsCollision(const LPGLVECTOR3& vpos, GLfloat radius) {
if(crush)
return 0;
if(IsCollisionSphere(&GLVECTOR3(pos.x, pos.y + 4.0f, pos.z), 3.3f, vpos, radius)) {
primary_task = 0;
if(--life > 0) {
uron = TRUE;
fsmoke = 1.0f;
crush = FALSE;
return 1;
} else {
uron = FALSE;
crush = TRUE;
cadrs = 0.0f;
time_crush = 0.0f;
snd_move->Stop();
return 2;
}
}
return 0;
}
void ResetTask(void) {
primary_task = 0;
}
void volume_ctrl(const LPGLVECTOR3& user_pos) {
GLfloat len = VectorLength(&(*user_pos - pos));
len = ABS(len);
if(len <= 150.0f)
snd_move->SetVolume(max(DSBVOLUME_MAX - len * 6L, DSBVOLUME_MIN));
}
};
// ñòðóêòóðà äëÿ ëåòàþùåãî ðîáîòà
struct sRobotFly {
GLVECTOR3 pos;
GLVECTOR3 vec;
GLfloat rotY;
GLfloat fangle;
int life;
BOOL uron;
BOOL crush;
GLfloat fsmoke;
GLVECTOR2 cadrs;
GLfloat time_crush;
enum {
TASK_PUSH = 0x1, // çàäàíèå ñêèíóòü áîìáó íà ïîëüçîâàòåëÿ ëþáîé öåíîé
TASK_MOVE = 0x2 // öåëü ïîë¸òà âûáèðàåòñÿ âî âðåìÿ èíèöèàëèçàöèè
};
int task;
static const int MAX_ROBOTS_FLY; // êîë-âî ðîáîòîâ â ñöåíå
sRobotFly(void): task(TASK_PUSH) {}
sRobotFly(const LPGLVECTOR3& user_pos, GLfloat x, GLfloat z) {
this->Initialize(user_pos, x, z);
}
// èíèöèàëèçàöèÿ
void Initialize(const LPGLVECTOR3& user_pos, GLfloat x, GLfloat z) {
pos.x = x;
pos.y = 90.0f + fRAND(1, 21);
pos.z = z;
life = 7;
fangle = 0.0f;
vec = 0.0f;
task = 1 + (rand() % 2);
uron = FALSE;
crush = FALSE;
if(task & TASK_MOVE) {
VectorSubtract(&vec, &pos, user_pos);
rotY = atan2f(vec.x, vec.z) * 180.0f / GL_PI;
VectorNormalize(&vec);
vec *= 0.9f;
vec.y = 0.0f;
}
}
// âñÿêèå ïîëåçíûå äåéñòâèÿ
void UpdateMove(const LPGLVECTOR3& user_pos, GLfloat cube, GLfloat felapsed, GLfloat ftime) {
if(crush)
return;
if(task & TASK_PUSH) { // ïîë¸ò ñ òàðàíîì
VectorSubtract(&vec, &pos, user_pos);
rotY = fDEGREE(atan2f(vec.x, vec.z));
VectorNormalize(&vec);
vec *= 0.9f;
pos -= vec * fNUM(felapsed, 24.0f);
} else if(task & TASK_MOVE) { // ïðîñòîé ïîë¸ò
pos -= vec * fNUM(felapsed, 24.0f);
if((pos.x > cube) || (pos.x < -cube) || (pos.z > cube) || (pos.z < -cube)) { // âñ¸ óëóòåëè çà êðàé ìèðà(skybox) ñ ãåíåðèðîâàòü íîâóþ ïîçèöèþ-çàäà÷ó
GLfloat rex = -cube + 10.0f;
GLfloat rez = -cube + fRAND(0, (int)cube * 2);
if((rand() % 2) != 0) {
rex = cube - 10.0f;
rez = cube + fRAND(1, (int)cube);
}
this->Initialize(user_pos, rex, rez);
}
}
fangle += fNUM(felapsed, 8.0f);
}
// âûâîä äûìà è âçðûâà
void DisplayEffect(const LPGLVECTOR3& user_pos, GLuint tex, GLfloat angleY, GLfloat felapsed, GLfloat ftime) {
GLVECTOR3 vpos;
if(uron) { // îáðàáîòêà óðîíà
xTextura::Set(tex);
fsmoke -= fNUM(felapsed, 1.4f);
xModel::DrawRect(&pos, fRAND(5, 9), angleY);
if(fsmoke < 0.1f)
uron = FALSE;
}
if(crush) { // îáðàáîòêà âçðûâà
const GLfloat cadr = 1.0f / 3.0f;
if((ftime - time_crush) > 70.0f) {
time_crush = ftime;
cadrs.x += cadr;
if(cadrs.x >= 1.0f) {
cadrs.x = 0.0f;
cadrs.y += cadr;
if(cadrs.y >= 1.0f) {
cadrs = 0.0f;
crush = FALSE;
GLfloat rex = -500 + 10.0f;
GLfloat rez = -500 + fRAND(0, (int)500 * 2);
if((rand() % 2) != 0) {
rex = 500 - 10.0f;
rez = -255 + fRAND(1, (int)500);
}
this->Initialize(user_pos, rex, rez);
return;
}
}
}
xTextura::Set(tex);
xModel::DrawAnimationSprite(&pos, &GLVECTOR3(5.0f, 5.0f, 0.0f), angleY, &cadrs, &GLVECTOR2(cadr));
}
}
// ïðîâåðêà òåêóùåé îïåðàöèè
int IsTaskPush(void) const {
return (task & TASK_PUSH);
}
BOOL IsCrush(void) const {
return crush;
}
BOOL IsUron(void) const {
return uron;
}
// ïðîâåðêà ñòîëêíîâåíèÿ ñ ïîëüçîâàòåëüñêîé ïóëåé
int IsCollision(const LPGLVECTOR3& vpos, GLfloat radius) {
if(crush)
return 0;
if(IsCollisionSphere(&pos, 6.0f, vpos, radius)) {
if(--life > 0) {
fsmoke = 1.0f;
uron = TRUE;
return 1;
} else {
uron = FALSE;
crush = TRUE;
cadrs = 0.0f;
time_crush = 0.0f;
return 2;
}
}
return 0;
}
};
// Êëàññ-êàðòà âûñîò, çàãðóæàåò êàðòó èç ôàéëà .RAW
class xTerrain {
// ñòðóêòóðà äëÿ ðàñòèòåëüíîñòè äåðåâî
struct sTree {
GLfloat x, y, z;
GLuint type;
sTree(void){}
sTree(GLuint type, GLfloat x, GLfloat y, GLfloat z) {
this->type = type;
this->x = x;
this->y = y;
this->z = z;
}
};
private:
GLuint tex_house[2];
GLuint tex;
GLuint tex_tree[4];
GLuint tex_smoke;
GLuint tex_crush;
GLfloat* vertices;
GLfloat* normals;
GLfloat* texs;
GLfloat* fmap;
GLfloat top_floor;
GLint vsize;
GLint tsize;
GLint vstep;
GLint map_size;
GLint map_rect;
GLint half_size;
GLuint vidlist;
xSound* snd_crush;
xSound* snd_uron;
xSound* snd_move[2];
std::vector<sTree> trees; // ðàñòèòåëüíîñòü êóñòû, äåðåâüÿ.
GLVECTOR3 houses[MAX_HOUSES];
GLVECTOR3 house_size;
int size_house;
GLfloat house_shadow[16];
xRobotFly robot_fly;
xRobotTM robot_tm;
sRobotFly robots_fly[2]; // 2 - ëåòàþùåãî ðîáîòà íà ýòîì õâàòèò
sRobotTM robots_tm[2]; // 2 - êàòàþùèõ ïî çåìëå ðîáîòà
public:
xTerrain(void);
~xTerrain();
public:
bool Create(LPDIRECTSOUND sound, GLint field_size, GLint step);
void Initialize(const LPGLVECTOR3& user_pos);
void Display(void);
void BeginMatrix(const LPGLVECTOR3& hpos);
void EndMatrix(void);
void Normalize(void);
bool LoadTerrain(const TCHAR* raw_filename, GLfloat scale = 0.08f);
void LoadTextura(const TCHAR* filename);
void Destroy(void);
void DisplayVegetations(const LPGLVECTOR3& user_pos, GLfloat angleY, GLfloat ftime, GLfloat felapsed);
void DisplayObjects(void);
void DisplayShadow(void);
void DisplayRobots(const LPGLVECTOR3& user_pos, GLfloat felapsed, GLfloat ftime);
void DisplayShadowRobots(const LPGLVECTOR4& light_pos);
void DisplayEffectRobots(const LPGLVECTOR3& user_pos, GLfloat angleY, GLfloat felapsed, GLfloat ftime);
void OffsetCameraY(LPGLVECTOR3 pos);
void SetTopFloor(GLfloat top);
void SetLightPos(const LPGLVECTOR4& light);
void RectOffset(GLint x, GLint z, GLfloat* arr);
void ObjectsToField(void);
GLfloat GetPlaneShadow(GLfloat* mat, LPGLVECTOR3 pos, const LPGLVECTOR4& light);
inline GLfloat Offset(GLint x, GLint y);
inline GLfloat GetOffsetTop(GLfloat x, GLfloat z);
void CollisionBullet(const LPGLVECTOR3& user_pos, std::list<sBullet>* plist);
bool CollisionUser(xCamera* camera, const LPGLVECTOR3& user_size);
GLuint GetVertexSize(void) const {
return vsize;
}
GLuint tSkull(void) {
return robot_tm.GetTex();
}
GLuint tHouse(int i) {
return tex_house[i];
}
GLfloat CubeSize(void) const {
return static_cast<GLfloat>(half_size - 90);
}
private:
void compile_tree(GLuint lid, GLuint tid, GLfloat x, GLfloat y);
void play_sound(const LPGLVECTOR3& va, const LPGLVECTOR3& vb, int code);
};
///////////////////////////////////////////////////////////////////////////////////////////////////
// êëàññ íåáåñíîãî êóáà
class xSkyBox {
private:
enum { MAX_TEXS = 5 };
GLuint listid;
GLuint texs[MAX_TEXS];
GLfloat width;
GLfloat height;
GLfloat depth;
public:
xSkyBox(void);
~xSkyBox();
public:
void Create(GLfloat width, GLfloat height, GLfloat depth, GLfloat h = 0.0f);
void Display(void);
bool Load(int index, const TCHAR* filename);
void Destroy(void);
};
#endif