-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMAZE.c
886 lines (722 loc) · 21.3 KB
/
AMAZE.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
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
//We were told to mark code we took from somewhere,
// I'm not sure how to mark down a friend teaching me
//almost everything, he also told me to look at his code for inspiration
// - so I did just that his repository is RG14-nerdbot-arena
#include<stdio.h>
#include<stdlib.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"
#define FILENAME1 "sand_2.bmp"
static GLuint names[2];
//variables for width and depth
extern int window_width = 0, window_height = 0;
//the incremental move variable
extern int move = 0;
//support indicator for deer-walking animation
int ind = 0;
//wolf animation parameters
extern int wolf_move = 0;
int wolf_ind = 0;
//patrolling parametors - they are used for every antagonist not just the wolf
int wolf_location = 0;
int wolf_rotation = 0;
int back_route = 0;
//Kaang animation
extern int Kaang_move = 0;
int Kaang_ind = 0;
//Whirly animation
extern int Whirly_move = 0;
//Abraxos animatoin
extern int Abraxos_move = 0;
int Abraxos_ind = 0;
//This really gets the deer going
int force_push = 0, side_force_push = 0;
//position of the deer in the MAZE matrix
extern int deer_i = -1, deer_j = 1;
//this tells us if the deer is in motion
extern int deer_motion = 0;
//how the deer turns
int deer_rotation = 0;
//last deer direction, this helps me navigate the matrix better
// w = 0, s = 1, a = 2, d = 3
extern int last_deer_direction = 0;
//camera indicators vertical w,s and horizontal a,d this helps move the camera
extern int ind_v = 1, ind_h = 0;
//maze matrix
int M[51][51];
int i=0, j=0;
//Encounter indicator - Encounter is a brief mini-game where you fight one of the antagonists
extern int En_ind = 0;
//deer encounter position - how the deer moves while in the Encounter
extern int deer_en_pos_v = 0;
extern int deer_en_pos_h = 0;
//indicator for my constant on_timer functions
extern int first_time_main_ind = 1;
//indicator that the game is over - mostly useless now (but I had big plans for it, alas ran out of time)
int end = 0;
//maze antagonist status indicators - 0 - the antagonist is drawn in the maze, 1 - he is not
int dead_Fenrys_1 = 0;
int dead_Fenrys_2 = 0;
int dead_Fenrys_3 = 0;
int dead_Kaang_1 = 0;
int dead_Kaang_2 = 0;
int dead_Kaang_3 = 0;
int dead_Whirly_1 = 0;
int dead_Whirly_2 = 0;
int dead_Whirly_3 = 0;
int dead_Abraxos_1 = 0;
int dead_Abraxos_2 = 0;
int dead_Abraxos_3 = 0;
//callback functions
static void on_display(void);
static void on_reshape(int width, int height);
extern void on_timer(int value);
static void on_timer_wolf(int value);
static void on_timer_Kaang(int value);
static void on_timer_Abraxos(int value);
int main(int argc, char** argv){
//initialization
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
//window initialization
glutInitWindowPosition(100,100);
glutInitWindowSize(1200,1200);
glutCreateWindow("AMAZE");
//calling the callback functions
glutDisplayFunc(on_display);
glutReshapeFunc(on_reshape);
glutKeyboardFunc(on_keyboard);
glutTimerFunc(20, on_timer_wolf, 0);
glutTimerFunc(20, on_timer_Kaang, 0);
glutTimerFunc(20, on_timer_Abraxos, 0);
//color that cleans the view
glClearColor(0.75, 0.75, 0.75, 0);
//Enable depth
glEnable(GL_DEPTH_TEST);
//Enable normalization of vectors
glEnable(GL_NORMALIZE);
//making the lines bolder
glLineWidth(3);
//entering the main loop
glutMainLoop();
return 0;
}
void on_display(void){
if(En_ind == 0){
if(deer_i == 49 && deer_j == 1){
end = 1;
printf("%d\n", end);
printf("Game Over! You Won!\n");
exit(0);
}
if(first_time_main_ind == 1){
glutTimerFunc(20, on_timer_wolf, 0);
glutTimerFunc(20, on_timer_Kaang, 0);
glutTimerFunc(20, on_timer_Abraxos, 0);
first_time_main_ind = 0;
}
//this segment is copied directly from a 'cas 7 - textures' code
//I dont understand it fully just the bits i need to make it work
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_read(image, FILENAME1);
glBindTexture(GL_TEXTURE_2D, names[1]);
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);
//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, 4, 1500);
//implementing the camera, when the deer turns it shifts with him, ind_h and ind_v regulate the shift
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(deer_i*2-ind_v*4+(0.1*force_push), deer_j*2-ind_h*4+(0.1*side_force_push), 5,
deer_i*2+(0.1*force_push)+2*ind_v, deer_j*2+(0.1*side_force_push)-0.01 + 2*ind_h, 2,
0, 0, 1);
//material parameters for the walls
//Blue
GLfloat diffuse_coeffs_B[] = { 0, 0, 0.7, 1};
GLfloat ambient_coeffs_B[] = { 0, 0, 0.7, 1};
//Green
GLfloat diffuse_coeffs_G[] = { 0, 0.7, 0, 1};
GLfloat ambient_coeffs_G[] = { 0, 0.7, 0, 1};
//Red
GLfloat diffuse_coeffs_R[] = { 0.7, 0, 0, 1};
GLfloat ambient_coeffs_R[] = { 0.7, 0, 0, 1};
//White
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.5, 0.5, 0.5, 1};
GLfloat shininess = 15;
glMaterialfv(GL_FRONT, GL_SPECULAR, specular_coeffs);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
//MAZE ground
glBindTexture(GL_TEXTURE_2D, names[0]);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2f(0, 0);
glVertex3f(-1, -1, 0);
glTexCoord2f(120, 0);
glVertex3f(101, 0, 0);
glTexCoord2f(120, 60);
glVertex3f(101, 101, 0);
glTexCoord2f(0, 60);
glVertex3f(0, 101, 0);
glEnd();
//outer sand land
glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_2D, names[1]);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2f(0, 0);
glVertex3f(-500, -500, -0.2);
glTexCoord2f(1200, 0);
glVertex3f(500, -500, -0.2);
glTexCoord2f(1200, 600);
glVertex3f(500, 500, -0.2);
glTexCoord2f(0, 600);
glVertex3f(-500, 500, -0.2);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
//file pointer
FILE *fp;
fp = fopen("MAZE.txt", "r");
//I wrote a matrix with ones and zeroes
//1 - there is a wall there 0 - there is no wall there
//here we scan that matrix from a file
for(i=0; i<50; i++){
for(j=0; j<50; j++){
if (!fscanf(fp, " %d", &M[i][j]))
break;
}
}
fclose(fp);
//here we draw the maze - different sections of the MAZE have different colors
for(i=0; i<50; i++){
for(j=0; j<50; j++){
if(M[i][j] == 1){
//here we pick the color of our wall block
if(i <=25 && j <= 25)
{
glColor3f(0,0,1);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_B);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_B);
}
else if(i <=25 && j > 25)
{
glColor3f(0,1,0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_G);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_G);
}
else if(i >25 && j <= 25)
{
glColor3f(1,0,0);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_R);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_R);
}
else if(i >25 && j > 25)
{
glColor3f(1,1,1);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient_coeffs_W);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse_coeffs_W);
}
//the wall block gets made and pushed to a correct position
glPushMatrix();
//the MAZE matrix helps place the wall block - only where the matrix value is 1
glTranslatef(2*i, 2*j, 5);
glScalef(2, 2, 10);
glutSolidCube(1);
glPopMatrix();
}
}
}
//everything is okay, beacuse our protagonist is here
//force_push and side_force_push propel our deer forward but the deer_i and deer_j truly place him
//they represent his place in the grand scheme of things(the MAZE Matrix)
//deer_rotation makes him turn
glPushMatrix();
glTranslatef(deer_i*2+(0.1*force_push), deer_j*2+(0.1*side_force_push), 0.5);
glRotatef(-90 + deer_rotation, 0, 0, 1);
glScalef(0.2, 0.2, 0.2);
DEER();
glPopMatrix();
//walking into a patrolled ground means there is gonna be an encounter
//the deer coordinates tell us if we entered that ground
if(deer_i == 14 && (deer_j >= 2 && deer_j <= 16) && dead_Fenrys_1 == 0){
//Encounter starts
En_ind = 1;
//the Foe is no longer drawn in the MAZE
dead_Fenrys_1 = 1;
}
if(deer_i == 5 && (deer_j >= 6 && deer_j <= 18) && dead_Fenrys_2 == 0){
dead_Fenrys_2 = 1;
En_ind = 1;
}
if(deer_i == 22 && (deer_j >= 9 && deer_j <= 20) && dead_Fenrys_3 == 0){
dead_Fenrys_3 = 1;
En_ind = 1;
}
if(deer_i == 1 && (deer_j >= 26 && deer_j <= 37) && dead_Kaang_1 == 0){
dead_Kaang_1 = 1;
En_ind = 1;
}
if(deer_i == 14 && (deer_j >= 37 && deer_j <= 49) && dead_Kaang_2 == 0){
dead_Kaang_2 = 1;
En_ind = 1;
}
if((deer_i >= 15 && deer_i <= 28) && deer_j == 41 && dead_Kaang_3 == 0){
dead_Kaang_3 = 1;
En_ind = 1;
}
if(deer_i == 29 && (deer_j >= 30 && deer_j <= 42) && dead_Whirly_1 == 0){
dead_Whirly_1 = 1;
En_ind = 1;
}
if((deer_i >= 32 && deer_i <= 43) && deer_j == 41 && dead_Whirly_2 == 0){
dead_Whirly_2 = 1;
En_ind = 1;
}
if(deer_i == 48 && (deer_j >= 27 && deer_j <= 39) && dead_Whirly_3 == 0){
dead_Whirly_3 = 1;
En_ind = 1;
}
if((deer_i >= 30 && deer_i <= 41) && deer_j == 1 && dead_Abraxos_1 == 0){
dead_Abraxos_1 = 1;
En_ind = 1;
}
if(deer_i == 47 && (deer_j >= 1 && deer_j <= 12) && dead_Abraxos_2 == 0){
dead_Abraxos_2 = 1;
En_ind = 1;
}
if((deer_i >= 36 && deer_i <= 44) && deer_j == 16 && dead_Abraxos_3 == 0){
dead_Abraxos_3 = 1;
En_ind = 1;
}
//here we have our antagonists they pretty much just walk through the MAZE
//if there was an encounter the foe doesnt get drawn anymore
//Wolf #1
if(dead_Fenrys_1 == 0){
glPushMatrix();
//the wolf is moved into position and set to patrolling
glTranslatef(28, 4 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
draw_wolf();
glPopMatrix();
}
if(dead_Fenrys_2 == 0)
{
//Wolf #2
glPushMatrix();
glTranslatef(10,14 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
draw_wolf();
glPopMatrix();
}
if(dead_Fenrys_3 == 0)
{
//Wolf #3
glPushMatrix();
glTranslatef(44,18 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.3, 0.3, 0.3);
draw_wolf();
glPopMatrix();
}
//Kaang #1
if(dead_Kaang_1 == 0){
glPushMatrix();
glTranslatef(2, 52 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.25, 0.25, 0.25);
draw_Kaang();
glPopMatrix();
}
//Kaang #2
if(dead_Kaang_2 == 0){
glPushMatrix();
//it says wolf everywhere but we can pretend it says something different
glTranslatef(28, 74 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.25, 0.25, 0.25);
draw_Kaang();
glPopMatrix();
}
//Kaang #3
if(dead_Kaang_3 == 0){
glPushMatrix();
glTranslatef(30 + 0.2*wolf_location, 82, 0.5);
glRotatef(-90 + wolf_rotation, 0, 0, 1);
glScalef(0.25, 0.25, 0.25);
draw_Kaang();
glPopMatrix();
}
//Whirly #1
if(dead_Whirly_1 == 0){
glPushMatrix();
glTranslatef(58, 52 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.15, 0.15, 0.3);
draw_Whirly();
glPopMatrix();
}
//Whirly #2
if(dead_Whirly_2 == 0){
glPushMatrix();
glTranslatef(64 + 0.2*wolf_location, 82, 0.5);
glRotatef(-90 + wolf_rotation, 0, 0, 1);
glScalef(0.15, 0.15, 0.3);
draw_Whirly();
glPopMatrix();
}
//Whirly #3
if(dead_Whirly_3 == 0){
glPushMatrix();
glTranslatef(96, 54 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.15, 0.15, 0.3);
draw_Whirly();
glPopMatrix();
}
//Abraxos #1
if(dead_Abraxos_1 == 0){
glPushMatrix();
glTranslatef(66 + 0.2*wolf_location, 2, 0.5);
glRotatef(-90 + wolf_rotation, 0, 0, 1);
glScalef(0.17, 0.17, 0.17);
draw_Abraxos();
glPopMatrix();
}
//Abraxos #2
if(dead_Abraxos_2 == 0){
glPushMatrix();
glTranslatef(94, 2 + 0.2*wolf_location, 0.5);
glRotatef(0 + wolf_rotation, 0, 0, 1);
glScalef(0.17, 0.17, 0.17);
draw_Abraxos();
glPopMatrix();
}
//Abraxos #3
if(dead_Abraxos_3 == 0){
glPushMatrix();
glTranslatef(72 + 0.2*wolf_location, 32, 0.5);
glRotatef(-90 + wolf_rotation, 0, 0, 1);
glScalef(0.17, 0.17, 0.17);
draw_Abraxos();
glPopMatrix();
}
}
//this is where we start the Encounter
//based on the deer location we know witch encounter started
//because foes never leave their designated territories
if(En_ind == 1){
if(deer_i<25 && deer_j<25)
Encounter(1);
if(deer_i<25 && deer_j>=25)
Encounter(2);
if(deer_i>=25 && deer_j>=25)
Encounter(3);
if(deer_i>=25 && deer_j<25)
Encounter(4);
}
// the picture gets drawn
glutSwapBuffers();
}
//when we reshape the window this function activates
static void on_reshape(int width, int height){
window_width = width;
window_height = height;
}
static void on_timer_Abraxos(int value){
//standard walking animation used everywhere
if(value == 0 && En_ind == 0){
if(Abraxos_ind == 1 && Abraxos_move <= -15)
Abraxos_ind = 0;
else if(Abraxos_ind == 1)
Abraxos_move -=1;
else if(Abraxos_move < 15)
Abraxos_move +=1;
else if(Abraxos_move >= 15)
Abraxos_ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer_Abraxos, 0);
}
}
static void on_timer_wolf(int value){
if(En_ind == 0){
//walking animation
if(wolf_ind == 1 && wolf_move <= -15)
wolf_ind = 0;
else if(wolf_ind == 1)
wolf_move -=2;
else if(wolf_move < 15)
wolf_move +=2;
else if(wolf_move >= 15)
wolf_ind = 1;
//patroling animation
if(wolf_location < 84 && back_route == 0){
wolf_location += 1;
glutPostRedisplay();
}
else if(wolf_location >= 84 && back_route == 0){
back_route = 1;
wolf_rotation = -180;
}
else if(wolf_location > 0 && back_route == 1)
{
wolf_location -= 1;
glutPostRedisplay();
}
else if(wolf_location <= 0 && back_route == 1){
back_route = 0;
wolf_rotation = 0;
}
glutPostRedisplay();
glutTimerFunc(40, on_timer_wolf, 0);
}
}
static void on_timer_Kaang(int value){
//whirly move animation
Whirly_move += 1;
//Kaang walking animation
if(En_ind == 0){
if(value == 0)
{
if(Kaang_ind == 1 && Kaang_move <= -30)
Kaang_ind = 0;
else if(Kaang_ind == 1)
Kaang_move -=1;
else if(Kaang_move < 30)
Kaang_move +=1;
else if(Kaang_move >= 30)
Kaang_ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer_Kaang, 0);
}
}
}
extern void on_timer(int value)
{
//this walking animation is so convoluted... What was I thinking
//going forward
if(value == 0 && deer_motion == 1)
{
//here we rotate the deer if rotation is required
if(deer_rotation > 0)
{
deer_rotation -= 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 0);
return;
}
if(deer_rotation < 0)
{
deer_rotation += 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 0);
return;
}
//because of this the deer moves forward
last_deer_direction = 0;
if(force_push<20)
force_push +=1;
else{
//when he has moved one space in the MAZE Matrix
//we update the deer location and reset everything else
force_push = 0;
deer_i = deer_i + 1;
move = 0;
deer_motion=0;
glutPostRedisplay();
return;
}
//this gives us the walking animation
if(ind == 1 && move <= -15)
ind = 0;
else if(ind == 1)
move -=1;
else if(move < 15)
move +=1;
else if(move >= 15)
ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 0);
}
//going backwards
if(value == 1 && deer_motion == 1)
{
if(deer_rotation > 180)
{
deer_rotation -= 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 1);
return;
}
if(deer_rotation < 180)
{
deer_rotation += 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 1);
return;
}
last_deer_direction = 1;
if(force_push>-20)
force_push -=1;
else{
force_push = 0;
deer_i = deer_i - 1;
move = 0;
deer_motion = 0;
glutPostRedisplay();
return;
}
if(ind == 1 && move <= -15)
ind = 0;
else if(ind == 1)
move -=1;
else if(move < 15)
move +=1;
else if(move >= 15)
ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 1);
}
//going left
if(value == 2 && deer_motion == 1)
{
if(deer_rotation > 90)
{
deer_rotation -= 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 2);
return;
}
if(deer_rotation < 90)
{
deer_rotation += 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 2);
return;
}
last_deer_direction = 2;
if(side_force_push<20)
side_force_push +=1;
else{
side_force_push = 0;
deer_j = deer_j + 1;
move = 0;
deer_motion = 0;
glutPostRedisplay();
return;
}
if(ind == 1 && move <= -15)
ind = 0;
else if(ind == 1)
move -=1;
else if(move < 15)
move +=1;
else if(move >= 15)
ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 2);
}
//going right
if(value == 3 && deer_motion == 1)
{
if(deer_rotation > -90)
{
deer_rotation -= 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 3);
return;
}
if(deer_rotation < -90)
{
deer_rotation += 10;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 3);
return;
}
last_deer_direction = 3;
if(side_force_push>-20)
side_force_push -=1;
else{
side_force_push = 0;
deer_j = deer_j - 1;
move = 0;
deer_motion = 0;
glutPostRedisplay();
return;
}
if(ind == 1 && move <= -15)
ind = 0;
else if(ind == 1)
move -=1;
else if(move < 15)
move +=1;
else if(move >= 15)
ind = 1;
glutPostRedisplay();
glutTimerFunc(20, on_timer, 3);
}
}