This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.c
199 lines (185 loc) · 4.87 KB
/
animate.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
#include "project.h"
/*
* BEGIN ANIMATION FUNCTIONS
*/
/*
* timer
* ------
* game animation logic turned on or off here
*/
void timer(int toggle)
{
if (gameStarted) {
if (gamePaused != DEF_GAME_PAUSED) {
moveLight();
moveTowerTops();
moveShots();
checkCollisions();
moveMinions();
checkCollisions();
checkTowerRange();
}
glutTimerFunc(50,timer,0);
}
redisplayAll();
}
/*
* slowAnimate
* ------
* step through the animation process
*/
void slowAnimate()
{
moveLight();
moveTowerTops();
moveShots();
checkCollisions();
moveMinions();
checkCollisions();
checkTowerRange();
}
/*
* moveLight
* ------
* move the light into position
*/
void moveLight(void)
{
if (moveLightB)
lightPh = (lightPh+2)%360;
}
/*
* moveMinion
* ------
* moves an individual minion i from wave k to fullPath j position
*/
void moveMinion(int k, int i, int j)
{
waves[k].m[i].translation.x = fullPath[j].p.x;
waves[k].m[i].translation.z = fullPath[j].p.z;
waves[k].m[i].rotation.y = fullPath[j].dir;
}
/*
* moveMinions
* ------
* moves every minion into its specific position
* This is horribly inefficient code
*/
void moveMinions(void)
{
int i,j,k;
/* for each wave (that is in play)
this allows for multiple waves at once moving along.
I'm currently not using this, so we're going to just check against the current waveNumber,
with a poor man's for loop so I don't have to re-write code
*/
// for (k=0;k<waveNumber;k++) {
for(k=waveNumber-1;k==waveNumber-1;k++) {
/* for each minion in the wave */
for (i=0;i<Length(waves[k].m);i++) {
int speed = waves[k].m[i].speed;
int damage = waves[k].m[i].damage;
/* Length(fullPath) = 2200... error about sizeof with structs */
for (j=0;j<(DEF_PATH_LEN*DEF_FULL_PATH_LEN);j += speed) {
/* if the minion is in play and in front of the keep, take damage and remove from play */
if (waves[k].m[i].inPlay == 1 &&
waves[k].m[i].translation.x <= -15 &&
waves[k].m[i].translation.z == 11) {
/* minion hurts you for X damage and gets removed from play */
modifyLives(1, damage);
waves[k].m[i].inPlay = 0;
break;
}
/* first minion */
if (i == 0) {
/* first time through */
if (waves[k].m[i].translation.x > 25) {
moveMinion(k,i,0);
break;
}
/* if we're at the previous position, increment by one */
else if(waves[k].m[i].translation.x == fullPath[j-speed].p.x &&
waves[k].m[i].translation.z == fullPath[j-speed].p.z) {
moveMinion(k,i,j);
break;
}
}
/* every other minion */
else {
/* stagger the planes - this technique won't work with different speeds of planes */
/* first time through */
if (fabs(waves[k].m[i-1].translation.x - waves[k].m[i].translation.x) >
((waves[k].m[i].scale.x)*20) ||
fabs(waves[k].m[i-1].translation.z - waves[k].m[i].translation.z) > 0) {
if (waves[k].m[i].translation.x > 25){
moveMinion(k,i,0);
break;
}
/* if we're at the previous position, increment by one */
else if(waves[k].m[i].translation.x == fullPath[j-speed].p.x &&
waves[k].m[i].translation.z == fullPath[j-speed].p.z) {
moveMinion(k,i,j);
break;
}
} /* end if for plane staggering */
} /* end else for every other minion (not the first) */
} /* end for each point in the fullPath */
} /* end for each minion in wave */
} /* end for each wave */
}
/*
* moveShot
* ------
* move an individual shot closer to a specific minion
* This is kind of choppy in that it moves at 90 degree angles and then goes straight
* Up the X/Z axis in order to hit the target
*/
void moveShot(int i, int j, int k)
{
/* determine the new direction vector for the shot to move towards based on minion */
point target = waves[j].m[k].translation;
point origin = shots[i].p;
double xFactor=0.0, zFactor=0.0;
if (target.x > origin.x)
xFactor = 0.5;
else if (target.x == origin.x)
xFactor = 0.0;
else if (target.x < origin.x)
xFactor = -0.5;
if (target.z > origin.z)
zFactor = 0.5;
else if (target.z == origin.z)
zFactor = 0.0;
else if (target.z < origin.z)
zFactor = -0.5;
shots[i].p.x += xFactor;
shots[i].p.z += zFactor;
}
/*
* moveShots
* ------
* moves the shots towards the farthest along minion in wave
*/
void moveShots(void)
{
int i,j;
for (i=0;i<lastShot;i++){
// shot s = shots[i];
for (j=0;j<Length(waves[waveNumber-1].m);j++) {
if (waves[waveNumber-1].m[j].inPlay) {
moveShot(i,waveNumber-1,j);
break; /* only fire move shot towards the first minion */
} /* end if minion in play */
} /* end for each minion in the last wave */
} /* end for until last shot */
}
/*
* moveTowerTops
* ------
* toggles moving the tower tops on or off
*/
void moveTowerTops(void)
{
if (moveTowerTopsB)
towerTh = (towerTh+2)%360;
}