-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncounter.c
868 lines (665 loc) · 21.3 KB
/
Encounter.c
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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
//this file is too big but I have to many files already
// and it has to many variables (it would be hard to link everything)
//and I'm out of time.. so...
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<stdbool.h>
#include<math.h>
#include "DEER.h"
#include "Fenrys.h"
#include "Kaang.h"
#include "Whirly.h"
#include "Abraxos.h"
#include "Keyboard.h"
#include "Encounter.h"
#include "image.h"
#include "Sword_and_shield.h"
#include "Powers.h"
#define FILENAME0 "brick4_b.bmp"
static GLuint names[2];
//animation timers
void wolf_attack_timer(int value);
void ice_blast_timer(int value);
void lightning_timer(int value);
//attack animation parameters
extern int first_time_ind = 0;
int wolf_attack = 0;
int ice_blast_1 = 0, ice_blast_2 = 0, ice_blast_3 = 0;
extern int ice_blast_move = 0;
//health
extern int deer_health = 5;
extern int foe_health = 5;
//so i know in timer functions witch foe im fighting
int bad_guy_here = 0;
//lightning animation
int lightning_strike_1 = 0;
int lightning_strike_2 = 0;
int lightning_strike_3 = 0;
int get_ready = 0;
int go = 0;
int lgh_hit = 0;
void Encounter(int bad_guy){
bad_guy_here = bad_guy;
//this whole section brings light to our MAZE
GLfloat light_position[] = {200.0f, 300.0f, 100.0f, 0.0f};
GLfloat light_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
GLfloat light_diffuse[] = {1, 1, 1, 1};
GLfloat light_specular[] = {0.9, 0.9, 0.9, 1};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//cleaning out the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//setting the view
glViewport(0, 0,window_width, window_height);
//Setting the angle, width-height ratio, near and far clipping plain
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, window_width/(float)window_height, 2, 1500);
//new camera position
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(50, 49, 5,
49.99, 40, 0,
0, 0, 1);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE,
GL_REPLACE);
Image * image;
image = image_init(0, 0);
image_read(image, FILENAME0);
glGenTextures(2, names);
glBindTexture(GL_TEXTURE_2D, names[0]);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
image->width, image->height, 0,
GL_RGB, GL_UNSIGNED_BYTE, image->pixels);
glBindTexture(GL_TEXTURE_2D, 0);
image_done(image);
//bad_guy == 1 -> we encountered the silver wolf Fenrys
if(bad_guy == 1)
{
//I want the timer to be called just once
if(first_time_ind == 0){
//seed for a random number generator
srand(time(NULL));
//attack animation - not just for the wolf but Im to lazy to change it
glutTimerFunc(20, wolf_attack_timer, 0);
first_time_ind = 1;
}
//water walls
GLfloat diffuse_coeffs_B[] = { 0, 0, 0.7, 1};
GLfloat ambient_coeffs_B[] = { 0, 0, 0.7, 1};
GLfloat specular_coeffs[] = { 0.3, 0.3, 0.3, 1};
GLfloat shininess = 5;
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_B);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_B);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_coeffs);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glPushMatrix();
glTranslatef(56, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(44, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(50, 0, 1);
glScalef(100, 1, 12);
glutSolidCube(1);
glPopMatrix();
//wolf is here
glPushMatrix();
glTranslatef(50, 20, 1);
glScalef(0.6, 0.6, 0.6);
draw_wolf();
glPopMatrix();
if(wolf_attack == 1){
//the wolfs attack is drawn here and animated with a timer function
if(ice_blast_1 == 1){
//ice blast #1
glPushMatrix();
glTranslatef(50, 23, 2);
glScalef(0.3, 0.3, 0.3);
draw_ice_blast();
glPopMatrix();
}
if(ice_blast_2 == 1){
//ice blast #2
glPushMatrix();
glTranslatef(52, 23, 2);
glScalef(0.3, 0.3, 0.3);
draw_ice_blast();
glPopMatrix();
}
if(ice_blast_3 == 1)
{
//ice blast #3
glPushMatrix();
glTranslatef(48, 23, 2);
glScalef(0.3, 0.3, 0.3);
draw_ice_blast();
glPopMatrix();
}
}
}
//bad_guy == 2 -> we encountered Kaang Kong
if(bad_guy == 2)
{
if(first_time_ind == 0){
srand(time(NULL));
glutTimerFunc(20, wolf_attack_timer, 0);
first_time_ind = 1;
}
//Earth walls
GLfloat diffuse_coeffs_G[] = { 0, 0.7, 0, 1};
GLfloat ambient_coeffs_G[] = { 0, 0.7, 0, 1};
GLfloat specular_coeffs[] = { 0.3, 0.3, 0.3, 1};
GLfloat shininess = 5;
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_G);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_G);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_coeffs);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glPushMatrix();
glTranslatef(56, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(44, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(50, 0, 1);
glScalef(100, 1, 12);
glutSolidCube(1);
glPopMatrix();
//Kaang kong
glPushMatrix();
glTranslatef(50, 20, 1);
glScalef(0.6, 0.6, 0.6);
draw_Kaang();
glPopMatrix();
//'Wolf'_attack
if(wolf_attack == 1){
//'ice'_blast - kaang weilds a staff
if(ice_blast_1 == 1){
//staff blast #1
glPushMatrix();
glTranslatef(50, 23, 2);
glRotatef(-90, 1, 0, 0);
draw_kaangs_staff();
glPopMatrix();
}
if(ice_blast_2 == 1){
//staff blast #2
glPushMatrix();
glTranslatef(52, 23, 2);
glRotatef(-90, 1, 0, 0);
draw_kaangs_staff();
glPopMatrix();
}
if(ice_blast_3 == 1)
{
//staff blast #3
glPushMatrix();
glTranslatef(48, 23, 2);
glRotatef(-90, 1, 0, 0);
draw_kaangs_staff();
glPopMatrix();
}
}
}
//bad_guy == 3 -> we encountered Whirly
if(bad_guy == 3)
{
if(first_time_ind == 0){
srand(time(NULL));
glutTimerFunc(20, wolf_attack_timer, 0);
first_time_ind = 1;
}
//Air walls
GLfloat diffuse_coeffs_W[] = { 0.7, 0.7, 0.7, 1};
GLfloat ambient_coeffs_W[] = { 0.7, 0.7, 0.7, 1};
GLfloat specular_coeffs[] = { 0.3, 0.3, 0.3, 1};
GLfloat shininess = 5;
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_W);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_W);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_coeffs);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glPushMatrix();
glTranslatef(56, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(44, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(50, 0, 1);
glScalef(100, 1, 12);
glutSolidCube(1);
glPopMatrix();
//Whirly
glPushMatrix();
glTranslatef(50, 20, 1);
glScalef(0.35, 0.35, 0.35);
draw_Whirly();
glPopMatrix();
if(wolf_attack == 1){
//gold
float mat_ambient_Gold[]={ 0.24725f, 0.1995f, 0.0745f, 1.0f };
float mat_diffuse_Gold[]={0.75164f, 0.60648f, 0.22648f, 1.0f };
float mat_specular_Gold[] ={0.628281f, 0.555802f, 0.366065f, 1.0f };
float shine_Gold =51.2f ;
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_Gold);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse_Gold);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_Gold);
glMaterialf(GL_FRONT, GL_SHININESS, shine_Gold);
//lightning attack is drawn here
if(lightning_strike_1 == 1)
{
if(get_ready == 1){
//this little sphere tells us where the lightning is gonna strike
glPushMatrix();
glTranslatef(50, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(50, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
if(lightning_strike_2 == 1)
{
if(get_ready == 1){
glPushMatrix();
glTranslatef(48, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(48, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
if(lightning_strike_3 == 1)
{
if(get_ready == 1){
glPushMatrix();
glTranslatef(52, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(52, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
//Silver
float mat_ambient_Silver[] ={ 0.19225f, 0.19225f, 0.19225f, 1.0f };
float mat_diffuse_Silver[] ={ 0.50754f, 0.50754f, 0.50754f, 1.0f};
float mat_specular_Silver[] ={0.508273f, 0.508273f, 0.508273f, 1.0f };
float shine_Silver = 51.2f;
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_Silver);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse_Silver);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_Silver);
glMaterialf(GL_FRONT, GL_SHININESS, shine_Silver);
GLUquadricObj *quadObj = gluNewQuadric();
//the wind attack gets drawn here and animated
if(ice_blast_1 == 1){
//wind blast #1
glPushMatrix();
glTranslatef(50 + sin(0.1*ice_blast_move), 23 + 0.4*ice_blast_move, 2);
glPushMatrix();
glRotatef(ice_blast_move, 0, 0, 1);
gluCylinder(quadObj, 0, 3, 10, 30, 30);
glPopMatrix();
glPopMatrix();
}
if(ice_blast_2 == 1){
//wind blast #2
glPushMatrix();
glTranslatef(52 + sin(0.1*ice_blast_move), 23 + 0.4*ice_blast_move, 2);
glPushMatrix();
glRotatef(ice_blast_move, 0, 0, 1);
gluCylinder(quadObj, 0, 3, 10, 30, 30);
glPopMatrix();
glPopMatrix();
}
if(ice_blast_3 == 1)
{
//ice blast #3
glPushMatrix();
glTranslatef(48 + sin(0.1*ice_blast_move), 23 + 0.4*ice_blast_move, 2);
glPushMatrix();
glRotatef(ice_blast_move, 0, 0, 1);
gluCylinder(quadObj, 0, 3, 10, 30, 30);
glPopMatrix();
glPopMatrix();
}
}
}
//bad_guy == 4 -> we encountered Abraxos
if(bad_guy == 4)
{
if(first_time_ind == 0){
srand(time(NULL));
glutTimerFunc(20, wolf_attack_timer, 0);
first_time_ind = 1;
}
//Fire walls
GLfloat diffuse_coeffs_R[] = { 0.7, 0, 0, 1};
GLfloat ambient_coeffs_R[] = { 0.7, 0, 0, 1};
GLfloat specular_coeffs[] = { 0.3, 0.3, 0.3, 1};
GLfloat shininess = 5;
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_R);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_R);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_coeffs);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glPushMatrix();
glTranslatef(56, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(44, 50, 1);
glScalef(1, 100, 12);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(50, 0, 1);
glScalef(100, 1, 12);
glutSolidCube(1);
glPopMatrix();
//Abraxos
glPushMatrix();
glTranslatef(50, 20, 1);
glScalef(0.38, 0.38, 0.38);
draw_Abraxos();
glPopMatrix();
if(wolf_attack == 1){
//gold
float mat_ambient_Gold[]={ 0.24725f, 0.1995f, 0.0745f, 1.0f };
float mat_diffuse_Gold[]={0.75164f, 0.60648f, 0.22648f, 1.0f };
float mat_specular_Gold[] ={0.628281f, 0.555802f, 0.366065f, 1.0f };
float shine_Gold =51.2f ;
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_Gold);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse_Gold);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_Gold);
glMaterialf(GL_FRONT, GL_SHININESS, shine_Gold);
if(lightning_strike_1 == 1)
{
if(get_ready == 1){
glPushMatrix();
glTranslatef(50, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(50, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
if(lightning_strike_2 == 1)
{
if(get_ready == 1){
glPushMatrix();
glTranslatef(48, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(48, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
if(lightning_strike_3 == 1)
{
if(get_ready == 1){
glPushMatrix();
glTranslatef(52, 22, 3);
glutSolidSphere(0.5, 30, 30);
glPopMatrix();
}
if(go == 1){
glPushMatrix();
glTranslatef(52, 23, 3);
draw_lightning_bolt();
glPopMatrix();
}
}
if(ice_blast_1 == 1){
//fire blast #1
glPushMatrix();
glTranslatef(50, 23 + 0.4*ice_blast_move, 2);
glScalef(0.5, 0.5, 0.5);
draw_fire_ball();
glPopMatrix();
}
if(ice_blast_2 == 1){
//fire blast #2
glPushMatrix();
glTranslatef(52, 23 + 0.4*ice_blast_move, 2);
glScalef(0.5, 0.5, 0.5);
draw_fire_ball();
glPopMatrix();
}
if(ice_blast_3 == 1)
{
//fire blast #3
glPushMatrix();
glTranslatef(48, 23 + 0.4*ice_blast_move, 2);
glScalef(0.5, 0.5, 0.5);
draw_fire_ball();
glPopMatrix();
}
}
}
if(deer_attack == 1){
glPushMatrix();
glTranslatef(50+2*deer_en_pos_v, 43-deer_attack_velocity, 1 + deer_en_pos_h);
glScalef(0.25, 0.25, 0.25);
glRotatef(45, 1, 0, 0);
//deer_attack - its a skewed triangle (yes thats the best idea I had)
glBegin(GL_TRIANGLES);
glNormal3f(0, 1, 0);
glVertex3f(0, 0, 2);
glVertex3f(6, 0, -1);
glVertex3f(0, 0, 0);
glNormal3f(0, 1, 0);
glVertex3f(0, 0, 2);
glVertex3f(-6, 0, -1);
glVertex3f(0, 0, 0);
glEnd();
glPopMatrix();
}
//our protagonist
glPushMatrix();
glTranslatef(50+2*deer_en_pos_v, 43, 1 + deer_en_pos_h);
glRotatef(180, 0, 0, 1);
glScalef(0.4, 0.4, 0.4);
DEER();
glPopMatrix();
//floor
glBindTexture(GL_TEXTURE_2D, names[0]);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 0);
glTexCoord2f(120, 0);
glVertex3f(100, 0, 0);
glTexCoord2f(120, 60);
glVertex3f(100, 100, 0);
glTexCoord2f(0, 60);
glVertex3f(0, 100, 0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
if(En_ind == 0){
return;
}
}
void ice_blast_timer(int value){
//well here we animate the attacks
//when they reach a certain point we check if the deer is there
//if he is we deduct a health point
if(En_ind == 1 && (bad_guy_here == 1 || bad_guy_here == 3 || bad_guy_here == 4)){
Whirly_move += 1;
if(0.3*ice_blast_move+8+23 <= 50){
ice_blast_move +=1;
glutPostRedisplay();
glutTimerFunc(20, ice_blast_timer, 0);
}
else if(0.3*ice_blast_move+8+23 > 50){
ice_blast_move = 0;
if((ice_blast_1 == 1 && deer_en_pos_v == 0) || (ice_blast_2 == 1 && deer_en_pos_v == 1)
|| (ice_blast_3 == 1 && deer_en_pos_v == -1)){
deer_health -= 1;
if(deer_health == 0){
printf("game over!\n");
exit(1);
}
}
return;
}
}
//the kaang animation needed to be pushed back a little beacuse his staff was large to begin with
if(En_ind == 1 && bad_guy_here == 2){
if(0.3*ice_blast_move+16+23 <= 50){
ice_blast_move +=1;
glutPostRedisplay();
glutTimerFunc(20, ice_blast_timer, 0);
}
else if(0.3*ice_blast_move+16+23 > 50){
ice_blast_move = 0;
if((ice_blast_1 == 1 && deer_en_pos_v == 0) || (ice_blast_2 == 1 && deer_en_pos_v == 1)
|| (ice_blast_3 == 1 && deer_en_pos_v == -1)){
deer_health -= 1;
if(deer_health == 0){
printf("game over!\n");
exit(1);
}
}
return;
}
}
}
void lightning_timer(int value){
//first we give a warning so the player can get ready
if(En_ind == 1 && value == 1 && get_ready == 0){
get_ready = 1;
glutPostRedisplay();
glutTimerFunc(200, lightning_timer, 1);
return;
}
//here the lightning strikes
if(En_ind == 1 && value == 1 && get_ready == 1){
go = 1;
get_ready = 0;
glutPostRedisplay();
if(deer_en_pos_v == 0 && lgh_hit == 0 && lightning_strike_1 == 1){
lgh_hit = 1;
deer_health -= 1;
}
if(deer_en_pos_v == -1 && lgh_hit == 0 && lightning_strike_2 == 1){
lgh_hit = 1;
deer_health -= 1;
}
if(deer_en_pos_v == -1 && lgh_hit == 0 && lightning_strike_3 == 1){
lgh_hit = 1;
deer_health -= 1;
}
if(deer_health == 0){
exit(1);
}
glutTimerFunc(100, lightning_timer, 2);
return;
}
//animation over reset everything
if(En_ind == 1 && value == 2){
go = 0;
if(lightning_strike_1 == 1)
lightning_strike_1 = 0;
if(lightning_strike_2 == 1)
lightning_strike_2 = 0;
if(lightning_strike_3 == 1)
lightning_strike_3 = 0;
lgh_hit = 0;
glutPostRedisplay();
return;
}
}
void wolf_attack_timer(int value){
if(value == 0 && En_ind == 1){
//random number that helps us randomize the attacks
int n = rand()%100+1;
//here we have 3 attack options decided by RNG
if(n < 33){
//clall to lightning
if(n%3 == 0 && lightning_strike_1 == 0 && (bad_guy_here == 3 || bad_guy_here == 4)){
lightning_strike_1 = 1;
glutTimerFunc(20, lightning_timer, 1);
}
wolf_attack = 1;
ice_blast_2 = 1;
ice_blast_3 = 1;
ice_blast_1 = 0;
glutTimerFunc(20, ice_blast_timer, 0);
}
else if(n >= 33 && n < 66){
if(n%3 == 0 && lightning_strike_2 == 0 && (bad_guy_here == 3 || bad_guy_here == 4)){
lightning_strike_2 = 1;
glutTimerFunc(20, lightning_timer, 1);
}
wolf_attack = 1;
ice_blast_1 = 1;
ice_blast_3 = 1;
ice_blast_2 = 0;
glutTimerFunc(20, ice_blast_timer, 0);
}
else{
if(n%3 == 0 && lightning_strike_3 == 0 && (bad_guy_here == 3 || bad_guy_here == 4)){
lightning_strike_3 = 1;
glutTimerFunc(20, lightning_timer, 1);
}
wolf_attack = 1;
ice_blast_1 = 1;
ice_blast_2 = 1;
ice_blast_3 = 0;
glutTimerFunc(20, ice_blast_timer, 0);
}
glutTimerFunc(1600, wolf_attack_timer, 0);
}
}