Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7047 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Feb 6, 2006, 1:29:09 PM (19 years ago)
Author:
bensch
Message:

trunk: added class Explosion

Location:
trunk/src
Files:
1 added
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/defs/class_id.h

    r7041 r7047  
    276276  // Particles
    277277  CL_PARTICLE_SYSTEM            =    0x00a01000,
    278   CL_SPRITE_PARTICLES           =    0x00000a01,
    279   CL_SPARK_PARTICLES            =    0x00000a02,
    280   CL_PNODE_PARTICLES            =    0x00000a03,
    281   CL_DOT_PARTICLES              =    0x00000a04,
    282   CL_MODEL_PARTICLES            =    0x00000a05,
     278  CL_SPRITE_PARTICLES           =    0x00002000,
     279  CL_SPARK_PARTICLES            =    0x00004000,
     280  CL_PNODE_PARTICLES            =    0x00008000,
     281  CL_DOT_PARTICLES              =    0x00010000,
     282  CL_MODEL_PARTICLES            =    0x00020000,
    283283
    284284  CL_PARTICLE_EMITTER           =    0x00a02000,
     
    295295  CL_FOG_EFFECT                 =    0x00000841,
    296296  CL_LENSE_FLARE                =    0x00000842,
     297  CL_EXPLOSION                  =    0x00000850,
    297298
    298299  // Element2D's  (range from 0x00000b00 to 0x00000bff)
  • trunk/src/world_entities/Makefile.am

    r7041 r7047  
    6565                  \
    6666                  world_entities/elements/image_entity.cc \
    67                   world_entities/elements/text_element.cc
     67                  world_entities/elements/text_element.cc \
     68                  \
     69                  world_entities/effects/explosion.cc
    6870
    6971
     
    128130                 \
    129131                 world_entities/elements/image_entity.h \
    130                  world_entities/elements/text_element.h
     132                 world_entities/elements/text_element.h \
     133                 \
     134                 world_entities/effects/explosion.h
    131135
     136
  • trunk/src/world_entities/effects/explosion.cc

    r7046 r7047  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1717
    18 #include "rocket.h"
     18#include "explosion.h"
    1919
    2020#include "fast_factory.h"
     
    2929using namespace std;
    3030
    31 CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET);
     31CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION);
    3232
    3333/**
    3434 *  standard constructor
    3535*/
    36 Rocket::Rocket () : Projectile()
     36Explosion::Explosion ()
    3737{
    38   this->setClassID(CL_ROCKET, "Rocket");
    39 
    40   float modelSize = .3;
    41   this->loadModel("models/projectiles/orx-rocket.obj", .3);
    42 
    43   this->setMinEnergy(1);
    44   this->setHealthMax(10);
    45   this->lifeSpan = 5;
     38  this->setClassID(CL_EXPLOSION, "Explosion");
    4639
    4740  this->emitter = new DotEmitter(100, 5, M_2_PI);
     41  this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    4842  this->emitter->setParent(this);
    4943  this->emitter->setSpread(M_PI, M_PI);
     44
     45  this->lifeCycle = 0.0f;
     46  this->lifeTime = 4.0f;
     47
    5048}
    5149
     
    5452 *  standard deconstructor
    5553*/
    56 Rocket::~Rocket ()
     54Explosion::~Explosion ()
    5755{
    58   // delete this->emitter;
     56  delete this->emitter;
    5957
    6058  /* this is normaly done by World.cc by deleting the ParticleEngine */
    61   if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1)
     59  if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1)
     60     Explosion::explosionParticles = NULL;
     61}
     62
     63SpriteParticles* Explosion::explosionParticles = NULL;
     64
     65void Explosion::activate()
     66{
     67  if (unlikely(Explosion::explosionParticles == NULL))
    6268  {
    63 /*    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM))
    64       delete Rocket::trailParticles;*/
    65     Rocket::trailParticles = NULL;
    66   }
    67   if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1)
    68   {
    69 /*    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM))
    70       delete Rocket::explosionParticles;*/
    71     Rocket::explosionParticles = NULL;
     69    Explosion::explosionParticles = new SpriteParticles(200);
     70    Explosion::explosionParticles->setName("ExplosionExplosionParticles");
     71    Explosion::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
     72    Explosion::explosionParticles->setLifeSpan(.5, .3);
     73    Explosion::explosionParticles->setRadius(0.0, 10);
     74    Explosion::explosionParticles->setRadius(.5, 15.0);
     75    Explosion::explosionParticles->setRadius(1.0, 10.0);
     76    Explosion::explosionParticles->setColor(0.0, 0,1,0,1);
     77    Explosion::explosionParticles->setColor(0.5, .8,.8,0,.8);
     78    Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.8);
     79    Explosion::explosionParticles->setColor(1.0, 1,1,1,.0);
    7280  }
    7381
    74 }
    75 
    76 SpriteParticles* Rocket::trailParticles = NULL;
    77 SpriteParticles* Rocket::explosionParticles = NULL;
    78 
    79 void Rocket::activate()
    80 {
    81   if (unlikely(Rocket::trailParticles == NULL))
    82   {
    83     Rocket::trailParticles = new SpriteParticles(2000);
    84     Rocket::trailParticles->setName("RocketTrailParticles");
    85     Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
    86     Rocket::trailParticles->setLifeSpan(1.0, .3);
    87     Rocket::trailParticles->setRadius(0.0, .5);
    88     Rocket::trailParticles->setRadius(0.2, 2.0);
    89     Rocket::trailParticles->setRadius(.5, .8);
    90     Rocket::trailParticles->setRadius(1.0, .8);
    91     Rocket::trailParticles->setColor(0.0, 1,0,0,.7);
    92     Rocket::trailParticles->setColor(0.2, .8,.8,0,.5);
    93     Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8);
    94     Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0);
    95   }
    96   if (unlikely(Rocket::explosionParticles == NULL))
    97   {
    98     Rocket::explosionParticles = new SpriteParticles(200);
    99     Rocket::explosionParticles->setName("RocketExplosionParticles");
    100     Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
    101     Rocket::explosionParticles->setLifeSpan(.5, .3);
    102     Rocket::explosionParticles->setRadius(0.0, 10);
    103     Rocket::explosionParticles->setRadius(.5, 15.0);
    104     Rocket::explosionParticles->setRadius(1.0, 10.0);
    105     Rocket::explosionParticles->setColor(0.0, 0,1,0,1);
    106     Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8);
    107     Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8);
    108     Rocket::explosionParticles->setColor(1.0, 1,1,1,.0);
    109   }
    110 
    111   this->emitter->setSystem(Rocket::trailParticles);
     82  this->emitter->setSystem(Explosion::explosionParticles);
    11283
    11384  this->updateNode(0);
    11485  this->emitter->setEmissionRate(45.0);
    11586  this->emitter->setEmissionVelocity(0.0);
     87  this->toList(OM_DEAD_TICK);
    11688}
    11789
    11890
    119 void Rocket::deactivate()
     91void Explosion::deactivate()
    12092{
    12193  this->emitter->setSystem(NULL);
    12294  this->lifeCycle = 0.0;
    123   this->toList(OM_NULL);
     95  this->toList(OM_DEAD);
    12496
    125 //  GarbageCollector::getInstance()->collect(this);
    126   this->toList(OM_DEAD);
    127   Rocket::fastFactory->kill(this);
     97  Explosion::fastFactory->kill(this);
    12898}
    12999
    130 
    131 void Rocket::collidesWith(WorldEntity* entity, const Vector& location)
    132 {
    133   if (this->hitEntity != entity)
    134     this->destroy();
    135   this->hitEntity = entity;
    136 }
    137100
    138101/**
     
    140103 * @param time since last tick
    141104*/
    142 void Rocket::tick (float dt)
     105void Explosion::tick (float dt)
    143106{
    144   //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
    145   Vector v = this->velocity * (dt);
    146   this->shiftCoor(v);
    147 
    148   if(this->tickLifeCycle(dt))
     107  this->lifeCycle += dt;
     108  if(this->lifeTime < this->lifeCycle)
    149109    this->deactivate();
    150110}
    151 
    152 /**
    153  *  the function gets called, when the projectile is destroyed
    154 */
    155 void Rocket::destroy ()
    156 {
    157   PRINTF(5)("DESTROY Rocket\n");
    158   this->lifeCycle = .95; //!< @todo calculate this usefully.
    159   this->emitter->setSystem(Rocket::explosionParticles);
    160 
    161   this->emitter->setEmissionRate(1000.0);
    162   this->emitter->setEmissionVelocity(50.0);
    163 //  this->deactivate();
    164 
    165 }
    166 
    167 
    168 void Rocket::draw () const
    169 {
    170   glMatrixMode(GL_MODELVIEW);
    171   glPushMatrix();
    172 
    173   float matrix[4][4];
    174   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
    175   this->getAbsDir().matrix (matrix);
    176   glMultMatrixf((float*)matrix);
    177   glScalef(2.0, 2.0, 2.0);
    178   this->getModel()->draw();
    179 
    180   glPopMatrix();
    181 }
    182 
  • trunk/src/world_entities/effects/explosion.h

    r7046 r7047  
    11/*!
    2  * @file rocket.h
    3  * @brief a Rocket Projectile
     2 * @file explosion.h
     3 * @brief a Explosion Projectile
    44*/
    55
    6 #ifndef _ROCKET_H
    7 #define _ROCKET_H
     6#ifndef _EXPLOSION_H
     7#define _EXPLOSION_H
    88
    9 #include "projectile.h"
     9#include "world_entity.h"
    1010
    11 class Vector;
    12 class Weapon;
    1311class SpriteParticles;
    1412class ParticleEmitter;
    1513class FastFactory;
    1614
    17 class Rocket : public Projectile
     15class Explosion : public WorldEntity
    1816{
    1917  public:
    20     Rocket ();
    21     virtual ~Rocket ();
    22 
     18    Explosion ();
     19    virtual ~Explosion ();
    2320
    2421    virtual void activate();
    2522    virtual void deactivate();
    2623
    27     virtual void collidesWith(WorldEntity* entity, const Vector& location);
    28 
    29     virtual void destroy ();
    30 
    3124    virtual void tick (float time);
    32     virtual void draw () const;
    33 
    3425
    3526  private:
    36     static FastFactory*               fastFactory;
    37     static SpriteParticles*           trailParticles;
     27    static FastFactory*        fastFactory;
     28
     29    float                      lifeTime;
     30    float                      lifeCycle;
     31
    3832    static SpriteParticles*           explosionParticles;
    39 
    40     ParticleEmitter*                  emitter;
    41 
    42 
    43     WorldEntity* hitEntity; // FIXME TEMPORARY
    44 
     33    ParticleEmitter*           emitter;
    4534};
    4635
    47 #endif /* _ROCKET_H */
     36#endif /* _EXPLOSION_H */
Note: See TracChangeset for help on using the changeset viewer.