-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocket.cpp
256 lines (221 loc) · 5.91 KB
/
rocket.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
// -----------------------------------------------------------------
// Learning Team B
// Members:
// Adam LeMmon
// Faith Satterthwaite
// Tom Fletcher
// Justin Ball
// CS 4280 – 11:30 am
// Final Project
// Dr. Rague
// Due: 12/06/12
// Version: 2.4
// -----------------------------------------------------------------
// We made five major improvements to this game
// 1) New controls
// 2) Enemy attack
// 3) HUD (heads up display)
// 4) Enemy health bars
// 5) New Weapon
// -----------------------------------------------------------------
#include "rocket.h"
CRocket::CRocket()
{
velocity = CVector(0.0, 0.0, 120.0);
acceleration = CVector(0.0, 0.0, 0.0);
distanceTravel = 0.0;
size = 1.0f;
isExplosion = false;
explosion = NULL;
explosionTex = new CTexture;
///// -- Adam
hitTarget = false;
isRocket = true;//this is a rocket and not a bullet
///// -- Adam
Load();
}
///// -- Adam
CRocket::CRocket(float s)
{
velocity = CVector(0.0, 0.0, s);
acceleration = CVector(0.0, 0.0, 0.0);
distanceTravel = 0.0;
size = 1;
isExplosion = false;
explosion = NULL;
explosionTex = new CTexture;
///// -- Adam
hitTarget = false;
isRocket = false;//let it know that this is a bullet and not a rocket
///// -- Adam
Load();
}
///// -- Adam
CRocket::~CRocket()
{
if (explosion != NULL)
{
explosion->KillSystem();
delete [] explosion;
explosion = NULL;
}
if (explosionTex != NULL)
{
delete explosionTex;
explosionTex = NULL;
}
}
void CRocket::SetupExplosionTexture()
{
glGenTextures(1, &explosionTex->texID);
glBindTexture(GL_TEXTURE_2D, explosionTex->texID);
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_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 4, explosionTex->width, explosionTex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, explosionTex->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, explosionTex->width, explosionTex->height, GL_RGBA, GL_UNSIGNED_BYTE, explosionTex->data);
}
void CRocket::OnAnimate(scalar_t deltaTime)
{
float cosYaw = (float)cos(DEG2RAD(direction));
float sinYaw = (float)sin(DEG2RAD(direction));
float sinPitch = (float)sin(DEG2RAD(pitch));
float speed = velocity.z * deltaTime;
position.x += float(cosYaw)*speed;
position.y += float(sinPitch)*speed;
position.z += float(sinYaw)*speed;
distanceTravel += position.Length();
if (isExplosion)
explosion->Update(deltaTime);
if (!isExplosion)
{
if (distanceTravel >= 500000.0f)
{
isExplosion = true;
velocity = CVector(0.0, 0.0, 0.0);
explosion = new CExplosion(10, position, 0.1f, explosionTex->texID);
}
}
}
void CRocket::OnCollision(CObject *collisionObject)
{
if (!isExplosion)
{
if (typeid(*collisionObject) == typeid(CTerrain))
{
if (((CTerrain*)collisionObject)->GetHeight(position.x, position.z) + size >= position.y)
{
isExplosion = true;
velocity = CVector(0.0, 0.0, 0.0);
///// -- Adam
if(isRocket == true)
{
///// -- Adam
explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
// Phase 19 - Uncomment the following
PlaySound();
///// -- Adam
}
else
{
explosion = new CExplosion(5, position, 1.0, explosionTex->texID);
}
///// -- Adam
}
// do explosion
}
if (typeid(*collisionObject) == typeid(COgroEnemy))
{
isExplosion = true;
velocity = CVector(0.0, 0.0, 0.0);
///// -- Adam
if(isRocket == true)
{
///// -- Adam
explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
// Phase 19 - Uncomment the following
PlaySound();
///// -- Adam
}
else
{
explosion = new CExplosion(5, position, 1.0, explosionTex->texID);
}
///// -- Adam
}
if (typeid(*collisionObject) == typeid(CSodEnemy))
{
isExplosion = true;
velocity = CVector(0.0, 0.0, 0.0);
///// -- Adam
if(isRocket == true)
{
///// -- Adam
explosion = new CExplosion(500, position, 8.0, explosionTex->texID);
// Phase 19 - Uncomment the following
PlaySound();
///// -- Adam
}
else
{
explosion = new CExplosion(5, position, 1.0, explosionTex->texID);
}
///// -- Adam
}
}
}
void CRocket::OnDraw(CCamera *camera)
{
// if the rocket has not yet exploded, draw the rocket model
if (!isExplosion)
{
glEnable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 1.0);
glTranslatef(position.x, position.y, position.z);
glRotatef(-direction, 0.0, 1.0, 0.0);
glScalef(0.025f, 0.025f, 0.025f);
RenderFrame(0);
glDisable(GL_TEXTURE_2D);
}
// draw explosion
else
{
// Phase 16 - take out fog commands until fog is defined
// Phase 20 - Uncomment fog statements
glDisable(GL_FOG);
explosion->Render();
glEnable(GL_FOG);
// Phase 16 - End
}
}
void CRocket::Load()
{
CMD2Model::Load("models\\rocketair.md2", "models\\rocket.pcx");
explosionTex->LoadTexture("explosion.bmp");
SetupExplosionTexture();
}
void CRocket::Unload()
{
}
void CRocket::OnPrepare()
{
// perform collision detection from this entity with all other objects in world
if (!isExplosion)
ProcessCollisions(FindRoot());
if (isExplosion)
{
// Phase 16 - Take out for now
// Phase 19 - Uncomment the following
if (explosion->IsDead())
{
explosion->KillSystem();
delete explosion;
explosion = NULL;
isExplosion = false;
isDead = true;
///// -- Adam
///// -- Adam
}
}
}