[4593] | 1 | /* |
---|
[3708] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
[5443] | 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
[3708] | 15 | */ |
---|
[5357] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3708] | 17 | |
---|
[5456] | 18 | #include "rocket.h" |
---|
[3708] | 19 | |
---|
[5443] | 20 | #include "state.h" |
---|
[5444] | 21 | #include "class_list.h" |
---|
[5054] | 22 | |
---|
[6822] | 23 | #include "dot_emitter.h" |
---|
[6621] | 24 | #include "sprite_particles.h" |
---|
[5443] | 25 | |
---|
[8362] | 26 | #include "debug.h" |
---|
[5443] | 27 | |
---|
[5456] | 28 | CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET); |
---|
[3708] | 29 | |
---|
| 30 | /** |
---|
[4836] | 31 | * standard constructor |
---|
[3708] | 32 | */ |
---|
[5456] | 33 | Rocket::Rocket () : Projectile() |
---|
[3755] | 34 | { |
---|
[6628] | 35 | this->setClassID(CL_ROCKET, "Rocket"); |
---|
[4597] | 36 | |
---|
[5499] | 37 | this->loadModel("models/projectiles/orx-rocket.obj", .3); |
---|
[4948] | 38 | |
---|
[6431] | 39 | this->setMinEnergy(1); |
---|
[6700] | 40 | this->setHealthMax(10); |
---|
[5819] | 41 | this->lifeSpan = 5; |
---|
[5443] | 42 | |
---|
[6825] | 43 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[5443] | 44 | this->emitter->setParent(this); |
---|
[5449] | 45 | this->emitter->setSpread(M_PI, M_PI); |
---|
[3755] | 46 | } |
---|
[3708] | 47 | |
---|
| 48 | |
---|
| 49 | /** |
---|
[4836] | 50 | * standard deconstructor |
---|
[3708] | 51 | */ |
---|
[5456] | 52 | Rocket::~Rocket () |
---|
[3708] | 53 | { |
---|
[5446] | 54 | // delete this->emitter; |
---|
[5444] | 55 | |
---|
[5445] | 56 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[6627] | 57 | if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) |
---|
[5447] | 58 | { |
---|
[6628] | 59 | /* if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM)) |
---|
| 60 | delete Rocket::trailParticles;*/ |
---|
[5456] | 61 | Rocket::trailParticles = NULL; |
---|
[5447] | 62 | } |
---|
[6627] | 63 | if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) |
---|
[5444] | 64 | { |
---|
[6628] | 65 | /* if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 66 | delete Rocket::explosionParticles;*/ |
---|
[5456] | 67 | Rocket::explosionParticles = NULL; |
---|
[5444] | 68 | } |
---|
[5445] | 69 | |
---|
[3708] | 70 | } |
---|
| 71 | |
---|
[6622] | 72 | SpriteParticles* Rocket::trailParticles = NULL; |
---|
| 73 | SpriteParticles* Rocket::explosionParticles = NULL; |
---|
[5443] | 74 | |
---|
[5456] | 75 | void Rocket::activate() |
---|
[5443] | 76 | { |
---|
[5456] | 77 | if (unlikely(Rocket::trailParticles == NULL)) |
---|
[5447] | 78 | { |
---|
[6621] | 79 | Rocket::trailParticles = new SpriteParticles(2000); |
---|
[5456] | 80 | Rocket::trailParticles->setName("RocketTrailParticles"); |
---|
[5471] | 81 | Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 82 | Rocket::trailParticles->setLifeSpan(1.0, .3); |
---|
[5456] | 83 | Rocket::trailParticles->setRadius(0.0, .5); |
---|
[5472] | 84 | Rocket::trailParticles->setRadius(0.2, 2.0); |
---|
| 85 | Rocket::trailParticles->setRadius(.5, .8); |
---|
[5471] | 86 | Rocket::trailParticles->setRadius(1.0, .8); |
---|
[5456] | 87 | Rocket::trailParticles->setColor(0.0, 1,0,0,.7); |
---|
[5472] | 88 | Rocket::trailParticles->setColor(0.2, .8,.8,0,.5); |
---|
| 89 | Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8); |
---|
[5471] | 90 | Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0); |
---|
[5447] | 91 | } |
---|
[5456] | 92 | if (unlikely(Rocket::explosionParticles == NULL)) |
---|
[5443] | 93 | { |
---|
[6621] | 94 | Rocket::explosionParticles = new SpriteParticles(200); |
---|
[5456] | 95 | Rocket::explosionParticles->setName("RocketExplosionParticles"); |
---|
[5471] | 96 | Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
[5693] | 97 | Rocket::explosionParticles->setLifeSpan(.5, .3); |
---|
[5456] | 98 | Rocket::explosionParticles->setRadius(0.0, 10); |
---|
[5693] | 99 | Rocket::explosionParticles->setRadius(.5, 15.0); |
---|
| 100 | Rocket::explosionParticles->setRadius(1.0, 10.0); |
---|
[5465] | 101 | Rocket::explosionParticles->setColor(0.0, 0,1,0,1); |
---|
| 102 | Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8); |
---|
| 103 | Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8); |
---|
[5456] | 104 | Rocket::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
[5443] | 105 | } |
---|
| 106 | |
---|
[6619] | 107 | this->emitter->setSystem(Rocket::trailParticles); |
---|
[5447] | 108 | |
---|
[5769] | 109 | this->updateNode(0); |
---|
[5472] | 110 | this->emitter->setEmissionRate(45.0); |
---|
[5471] | 111 | this->emitter->setEmissionVelocity(0.0); |
---|
[5443] | 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
[5456] | 115 | void Rocket::deactivate() |
---|
[5443] | 116 | { |
---|
[6619] | 117 | this->emitter->setSystem(NULL); |
---|
[5447] | 118 | this->lifeCycle = 0.0; |
---|
[6142] | 119 | this->toList(OM_NULL); |
---|
[5443] | 120 | |
---|
[5447] | 121 | // GarbageCollector::getInstance()->collect(this); |
---|
[6142] | 122 | this->toList(OM_DEAD); |
---|
[5456] | 123 | Rocket::fastFactory->kill(this); |
---|
[5443] | 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
[5456] | 127 | void Rocket::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5257] | 128 | { |
---|
[6433] | 129 | if (this->hitEntity != entity) |
---|
[5447] | 130 | this->destroy(); |
---|
| 131 | this->hitEntity = entity; |
---|
[5257] | 132 | } |
---|
[3708] | 133 | |
---|
| 134 | /** |
---|
[4836] | 135 | * signal tick, time dependent things will be handled here |
---|
| 136 | * @param time since last tick |
---|
[3708] | 137 | */ |
---|
[6056] | 138 | void Rocket::tick (float dt) |
---|
[3708] | 139 | { |
---|
[4464] | 140 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
[6056] | 141 | Vector v = this->velocity * (dt); |
---|
[3708] | 142 | this->shiftCoor(v); |
---|
| 143 | |
---|
[6056] | 144 | if(this->tickLifeCycle(dt)) |
---|
| 145 | this->deactivate(); |
---|
[3708] | 146 | } |
---|
| 147 | |
---|
| 148 | /** |
---|
[4836] | 149 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 150 | */ |
---|
[5456] | 151 | void Rocket::destroy () |
---|
[5257] | 152 | { |
---|
[7086] | 153 | Projectile::destroy(); |
---|
| 154 | |
---|
[5456] | 155 | PRINTF(5)("DESTROY Rocket\n"); |
---|
[5448] | 156 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[6619] | 157 | this->emitter->setSystem(Rocket::explosionParticles); |
---|
[3708] | 158 | |
---|
[5465] | 159 | this->emitter->setEmissionRate(1000.0); |
---|
[5447] | 160 | this->emitter->setEmissionVelocity(50.0); |
---|
| 161 | // this->deactivate(); |
---|
[3708] | 162 | |
---|
[5257] | 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
[5500] | 166 | void Rocket::draw () const |
---|
[3708] | 167 | { |
---|
| 168 | glMatrixMode(GL_MODELVIEW); |
---|
| 169 | glPushMatrix(); |
---|
| 170 | |
---|
[4593] | 171 | float matrix[4][4]; |
---|
[3708] | 172 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 173 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 174 | glMultMatrixf((float*)matrix); |
---|
[3755] | 175 | glScalef(2.0, 2.0, 2.0); |
---|
[5994] | 176 | this->getModel()->draw(); |
---|
[3708] | 177 | |
---|
| 178 | glPopMatrix(); |
---|
| 179 | } |
---|
| 180 | |
---|