#include <gExplosion.h>
Public Member Functions | |
gExplosion (eGrid *grid, const eCoord &pos, REAL time, gRealColor &color, gCycle *owner) | |
virtual | ~gExplosion () |
virtual bool | Timestep (REAL currentTime) |
virtual void | InteractWith (eGameObject *target, REAL time, int recursion=1) |
virtual void | PassEdge (const eWall *w, REAL time, REAL a, int recursion=1) |
virtual void | Kill () |
destroys the gameobject (in the game) | |
virtual void | Render (const eCamera *cam) |
draws object to the screen using OpenGL | |
virtual void | Render2D (tCoord scale) const |
bool | AccountForHole () |
gCycle * | GetOwner () const |
Static Public Member Functions | |
static void | OnNewWall (eWall *w) |
Public Attributes | |
int | particle_handle_circle |
int | particle_handle_cylinder |
Protected Member Functions | |
virtual void | OnRemoveFromGame () |
called on RemoveFromGame(). Call base class implementation, too, in your implementation. Must keep the object alive. | |
Private Attributes | |
REAL | createTime |
REAL | explosion_r |
REAL | explosion_g |
REAL | explosion_b |
int | expansion |
bool | holeAccountedFor_ |
flag indicating whether we already gave the player credit for making a hole for his teammates | |
int | listID |
tJUST_CONTROLLED_PTR< gCycle > | owner_ |
Static Private Attributes | |
static int | expansionSteps = 5 |
static REAL | expansionTime = 0.2f |
Definition at line 36 of file gExplosion.h.
gExplosion::gExplosion | ( | eGrid * | grid, | |
const eCoord & | pos, | |||
REAL | time, | |||
gRealColor & | color, | |||
gCycle * | owner | |||
) |
Definition at line 141 of file gExplosion.cpp.
References tList< T, MALLOC, REFERENCE >::Add(), eGameObject::AddToList(), gRealColor::b, CYCLE_EXPLOSION, explosion_b, explosion_g, explosion_r, gRealColor::g, eSoundMixer::GetMixer(), holeAccountedFor_, eGameObject::lastTime, listID, eSoundMixer::PushButton(), gRealColor::r, and eGameObject::z.
00142 :eReferencableGameObject(grid, pos, eCoord(0,0), NULL, true), 00143 createTime(time), 00144 expansion(0), 00145 listID(-1), 00146 owner_(owner) 00147 { 00148 eSoundMixer* mixer = eSoundMixer::GetMixer(); 00149 mixer->PushButton(CYCLE_EXPLOSION, pos); 00150 //std::cout << "explosion sound effect\n"; 00151 holeAccountedFor_ = false; 00152 00153 lastTime = time; 00154 explosion_r = color.r; 00155 explosion_g = color.g; 00156 explosion_b = color.b; 00157 //std::cout << "about to do sg_Explosions.Add\n"; 00158 sg_Explosions.Add( this, listID ); 00159 z=0; 00160 //std::cout << "explosion constructed\n"; 00161 #ifdef USEPARTICLES 00162 //std::cout << "Using particle explosion\n"; 00163 // particle_handle_circle = pGenParticleGroups(1, 10); 00164 // particle_handle_cylinder = pGenParticleGroups(1, 1000); 00165 00166 // pCurrentGroup(particle_handle_circle); 00167 // Generate particles along a very small line in the nozzle. 00168 // pSource(1000, PDSphere(pVec(pos.x, pos.y, 0.3), 0.2)); 00169 // pCurrentGroup(particle_handle_cylinder); 00170 // Generate particles along a very small line in the nozzle. 00171 // pSource(1000, PDSphere(pVec(Position().x, Position().y, 0.3), 0.2)); 00172 #endif 00173 00174 // add to game object lists 00175 AddToList(); 00176 //std::cout << "Last line of constructor\n"; 00177 }
gExplosion::~gExplosion | ( | ) | [virtual] |
Definition at line 179 of file gExplosion.cpp.
References listID, tList< T, MALLOC, REFERENCE >::Remove(), and s_explosionRadius.
00179 { 00180 sg_Explosions.Remove( this, listID ); 00181 00182 if ( s_explosionRadius > 0 ) 00183 { 00184 /* 00185 s_explosionCoord = pos; 00186 s_explosionRadius = gCycle::ExplosionRadius()*1.5f; 00187 00188 grid->ProcessWallsInRange( &S_Sync, 00189 s_explosionCoord, 00190 s_explosionRadius, 00191 this->CurrentFace() ); 00192 */ 00193 } 00194 }
bool gExplosion::Timestep | ( | REAL | currentTime | ) | [virtual] |
Reimplemented from eGameObject.
Definition at line 199 of file gExplosion.cpp.
References createTime, expansion, expansionSteps, expansionTime, gCycle::ExplosionRadius(), eGameObject::lastTime, eGameObject::pos, REAL, S_BlowHoles(), s_explosionCoord, s_explosionRadius, s_explosionTime, and sqrt().
00199 { 00200 lastTime=currentTime; 00202 00203 int currentExpansion = int(REAL( expansionSteps )*((currentTime - createTime)/expansionTime)) + 1; 00204 if ( currentExpansion > expansionSteps ) 00205 currentExpansion = expansionSteps; 00206 00207 if ( currentExpansion > expansion ) 00208 { 00209 expansion = currentExpansion; 00210 00211 s_explosionCoord = pos; 00212 REAL factor = expansion / REAL( expansionSteps ); 00213 s_explosionRadius = gCycle::ExplosionRadius() * sqrt(factor); 00214 s_explosionTime = currentTime; 00215 s_holer = this; 00216 00217 if ( s_explosionRadius > 0 && (currentTime < createTime+4) ) 00218 { 00219 grid->ProcessWallsInRange( &S_BlowHoles, 00220 s_explosionCoord, 00221 s_explosionRadius, 00222 this->CurrentFace() ); 00223 } 00224 00225 s_holer = 0; 00226 } 00227 #ifndef USEPARTICLES 00228 00229 /* 00230 // see every once in a while if all cycles did a turn since the expl was created 00231 if ( expansion >= expansionSteps ) 00232 { 00233 currentExpansion = expansionSteps + 1 + int( REAL( expansion ) * ( currentTime - createTime ) ); 00234 } 00235 if ( currentExpansion > expansion ) 00236 { 00237 expansion = currentExpansion; 00238 REAL time = createTime + 5.0f; 00239 00240 const tList<eGameObject>& gameObjects = this->Grid()->GameObjects(); 00241 for ( int i = gameObjects.Len() - 1; i>=0; --i ) 00242 { 00243 eGameObject* o = gameObjects( i ); 00244 00245 gCycle* c = dynamic_cast< gCycle* >( o ); 00246 if ( c && c->Alive() ) 00247 { 00248 const gPlayerWall* w = c->CurrentWall(); 00249 00250 if ( !w || w->BegTime() < time || w->EndTime() < time ) 00251 { 00252 // c has not made a turn; we need to stay around some more 00253 return false; 00254 } 00255 } 00256 } 00257 } 00258 */ 00259 if (currentTime>createTime+4) 00260 return true; 00261 else 00262 return false; 00263 #else 00264 /* pCurrentGroup(particle_handle_circle); 00265 // Set up the state. 00266 pExplosion(Position().x, Position().y, 0.3, 20.0, 20.0, 1.0); 00267 //pVelocityD(PDCylinder(pVec(0.0, 0.0, 0.0), pVec(0.0, 0.0, 0.01), 0.01, 0.007)); 00268 pColorD(PDLine(pVec(1.0, 1.0, 1.0), pVec(1.0, 1.0, 1.0))); 00269 pSize(40.0); 00270 //pStartingAge(0); 00271 00272 //pRandomAccel(PDSphere(pVec(Position().x, Position().y, 0.0), 100.0)); 00273 00274 // Bounce particles off the grid floor. 00275 pBounce(-0.05, 1.0, 0.1, PDDisc(pVec(0, 0, 0), pVec(0, 0, 1), 5000000)); 00276 00277 pKillOld(400.0); 00278 00279 // Move particles to their new positions. 00280 pMove(); 00281 00282 // Finished when there are less than 1/10 of the original particles 00283 if (pGetGroupCount() < 100) { 00284 pDeleteParticleGroups(particle_handle_circle, particle_handle_circle); 00285 return true; 00286 } else 00287 return false;*/ 00288 //std::cout << "returning from timestep\n"; 00289 if (currentTime>createTime+4) 00290 return true; 00291 else 00292 return false; 00293 #endif
void gExplosion::InteractWith | ( | eGameObject * | target, | |
REAL | time, | |||
int | recursion = 1 | |||
) | [virtual] |
void gExplosion::Kill | ( | ) | [virtual] |
destroys the gameobject (in the game)
Reimplemented from eGameObject.
Definition at line 299 of file gExplosion.cpp.
References createTime, and eGameObject::lastTime.
00300 { 00301 createTime=lastTime-100;
void gExplosion::Render | ( | const eCamera * | cam | ) | [virtual] |
draws object to the screen using OpenGL
Reimplemented from eGameObject.
Definition at line 364 of file gExplosion.cpp.
References BeginLines(), createTime, explosion_b, explosion_g, explosion_r, eGameObject::lastTime, GrowingArrayBase::Len(), ModelMatrix(), eGameObject::pos, REAL, RenderEnd(), sg_crashExplosion, and x.
00365 { 00366 //std::cout << "Starting render\n"; 00367 #ifdef USEPARTICLES 00368 /*if(sg_crashExplosion){ 00369 ModelMatrix(); 00370 glPushMatrix(); 00371 pCurrentGroup(particle_handle_circle); 00372 int cnt = (int)pGetGroupCount(); 00373 if(cnt < 1) return; 00374 00375 float *ptr; 00376 size_t flstride, pos3Ofs, posB3Ofs, size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs; 00377 00378 cnt = (int)pGetParticlePointer(ptr, flstride, pos3Ofs, posB3Ofs, 00379 size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs); 00380 if(cnt < 1) return; 00381 00382 glEnableClientState(GL_COLOR_ARRAY); 00383 glColorPointer(4, GL_FLOAT, int(flstride) * sizeof(float), ptr + color3Ofs); 00384 00385 glEnableClientState(GL_VERTEX_ARRAY); 00386 glVertexPointer(3, GL_FLOAT, int(flstride) * sizeof(float), ptr + pos3Ofs); 00387 00388 glDrawArrays(GL_POINTS, 0, cnt); 00389 glDisableClientState(GL_VERTEX_ARRAY); 00390 glDisableClientState(GL_COLOR_ARRAY); 00391 glPopMatrix(); 00392 }*/ 00393 #else 00394 if (sg_crashExplosion){ 00395 REAL a1=(lastTime-createTime)+.01f;//+.2; 00396 REAL e=a1-1; 00397 00398 if (e<0) e=0; 00399 00400 REAL fade=(2-a1); 00401 if (fade<0) fade=0; 00402 if (fade>1) fade=1; 00403 00404 a1*=100; 00405 e*=100; 00406 00407 ModelMatrix(); 00408 glPushMatrix(); 00409 glTranslatef(pos.x,pos.y,0); 00410 00411 //glDisable(GL_TEXTURE); 00412 glDisable(GL_TEXTURE_2D); 00413 00414 glColor4f(explosion_r,explosion_g,explosion_b,fade); 00415 BeginLines(); 00416 for (int i=expvec.Len()-1;i>=0;i--){ 00417 glVertex3f(a1*expvec[i].x[0],a1*expvec[i].x[1],a1*expvec[i].x[2]); 00418 glVertex3f( e*expvec[i].x[0], e*expvec[i].x[1], e*expvec[i].x[2]); 00419 } 00420 RenderEnd(); 00421 glPopMatrix(); 00422 } 00423 /* 00424 if(sr_alphaBlend) 00425 for(int i=2;i>=0;i--){ 00426 REAL age=a1-i*.1; 00427 if (0<age && age<.5){ 00428 REAL alpha=(3-i)*.5*(1-age*2)*(1-age*2); 00429 glColor4f(r,g,b,alpha); 00430 glDisable(GL_LIGHTING); 00431 glDisable(GL_TEXTURE_2D); 00432 glMatrixMode(GL_MODELVIEW); 00433 glPushMatrix(); 00434 glTranslatef(pos.x,pos.y,age*pow((age+1),3)*(age+.5)*100); 00435 y 00436 00437 GLUquadricObj* q= gluNewQuadric(); 00438 00439 gluSphere(q,(age*pow((age+1),3)*(age+.5))*100,5,5); 00440 00441 gluDeleteQuadric( q ); 00442 00443 glPopMatrix(); 00444 } 00445 } 00446 */ 00447 #endif 00448 //std::cout << "Finishing render\n";
void gExplosion::Render2D | ( | tCoord | scale | ) | const [virtual] |
Reimplemented from eGameObject.
Definition at line 450 of file gExplosion.cpp.
References BeginLines(), createTime, explosion_b, explosion_g, explosion_r, eGameObject::lastTime, GrowingArrayBase::Len(), ModelMatrix(), eGameObject::pos, REAL, RenderEnd(), sg_crashExplosionHud, and x.
00451 { 00452 #ifndef DEDICATED 00453 if(sg_crashExplosionHud){ 00454 REAL a1=(lastTime-createTime)+.01f;//+.2; 00455 REAL e=a1-1; 00456 00457 if (e<0) e=0; 00458 00459 REAL fade=(2-a1); 00460 if (fade<0) fade=0; 00461 if (fade>1) fade=1; 00462 00463 a1*=100; 00464 e*=100; 00465 00466 ModelMatrix(); 00467 glPushMatrix(); 00468 glTranslatef(pos.x,pos.y,0); 00469 00470 glDisable(GL_TEXTURE_2D); 00471 00472 glColor4f(explosion_r,explosion_g,explosion_b,fade); 00473 BeginLines(); 00474 for(int i=expvec.Len()-1;i>=0;i--){ 00475 glVertex2f(a1*expvec[i].x[0],a1*expvec[i].x[1]); 00476 glVertex2f( e*expvec[i].x[0], e*expvec[i].x[1]); 00477 } 00478 RenderEnd(); 00479 glPopMatrix(); 00480 } 00481 #endif 00482 //std::cout << "Finishing render\n";
bool gExplosion::AccountForHole | ( | ) |
Definition at line 303 of file gExplosion.cpp.
References holeAccountedFor_.
Referenced by gCycle::PassEdge().
00305 { 00306 bool ret = !holeAccountedFor_; 00307 holeAccountedFor_ = true; 00308 return ret;
void gExplosion::OnNewWall | ( | eWall * | w | ) | [static] |
Definition at line 310 of file gExplosion.cpp.
References createTime, expansion, expansionSteps, gCycle::ExplosionRadius(), GrowingArrayBase::Len(), eGameObject::pos, S_BlowHoles(), s_explosionCoord, s_explosionRadius, s_explosionTime, and sg_Explosions.
00312 { 00313 for ( int i = sg_Explosions.Len() - 1; i>=0; --i ) 00314 { 00315 const gExplosion* e = sg_Explosions(i); 00316 if ( e->expansion >= expansionSteps ) 00317 { 00318 // e is a already completed explosion 00319 s_explosionCoord = e->pos; 00320 s_explosionRadius = gCycle::ExplosionRadius(); 00321 s_explosionTime = e->createTime; 00322 00323 S_BlowHoles( w ); 00324 } 00325 }
gCycle* gExplosion::GetOwner | ( | ) | const [inline] |
Definition at line 67 of file gExplosion.h.
References owner_.
Referenced by gCycle::PassEdge().
00068 { 00069 return owner_; 00070 }
void gExplosion::OnRemoveFromGame | ( | ) | [protected, virtual] |
called on RemoveFromGame(). Call base class implementation, too, in your implementation. Must keep the object alive.
Reimplemented from eGameObject.
Definition at line 495 of file gExplosion.cpp.
References listID, eGameObject::OnRemoveFromGame(), and tList< T, MALLOC, REFERENCE >::Remove().
00497 { 00498 // remove from list to avoid costy checks whenever a new wall appears 00499 sg_Explosions.Remove( this, listID ); 00500 00501 // delegate to base 00502 eReferencableGameObject::OnRemoveFromGame();
Definition at line 62 of file gExplosion.h.
Definition at line 63 of file gExplosion.h.
REAL gExplosion::createTime [private] |
Definition at line 76 of file gExplosion.h.
Referenced by Kill(), OnNewWall(), Render(), Render2D(), and Timestep().
REAL gExplosion::explosion_r [private] |
REAL gExplosion::explosion_g [private] |
REAL gExplosion::explosion_b [private] |
int gExplosion::expansion [private] |
int gExplosion::expansionSteps = 5 [static, private] |
REAL gExplosion::expansionTime = 0.2f [static, private] |
bool gExplosion::holeAccountedFor_ [private] |
flag indicating whether we already gave the player credit for making a hole for his teammates
Definition at line 88 of file gExplosion.h.
Referenced by AccountForHole(), and gExplosion().
int gExplosion::listID [private] |
Definition at line 90 of file gExplosion.h.
Referenced by gExplosion(), OnRemoveFromGame(), and ~gExplosion().
tJUST_CONTROLLED_PTR< gCycle > gExplosion::owner_ [private] |