[9217] | 1 | |
---|
[4593] | 2 | /* |
---|
[3708] | 3 | orxonox - the future of 3D-vertical-scrollers |
---|
| 4 | |
---|
| 5 | Copyright (C) 2004 orx |
---|
| 6 | |
---|
| 7 | This program is free software; you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU General Public License as published by |
---|
| 9 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 10 | any later version. |
---|
| 11 | |
---|
| 12 | ### File Specific |
---|
[5759] | 13 | main-programmer: Silvan Nellen |
---|
| 14 | co-programmer: |
---|
[5443] | 15 | |
---|
[3708] | 16 | */ |
---|
[5357] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3708] | 18 | |
---|
[9217] | 19 | #include "boomerang_projectile.h" |
---|
[3708] | 20 | |
---|
[5443] | 21 | #include "state.h" |
---|
[5444] | 22 | #include "class_list.h" |
---|
[5054] | 23 | |
---|
[6822] | 24 | #include "dot_emitter.h" |
---|
[6621] | 25 | #include "sprite_particles.h" |
---|
[5443] | 26 | |
---|
[8362] | 27 | #include "debug.h" |
---|
[3708] | 28 | |
---|
[9217] | 29 | CREATE_FAST_FACTORY_STATIC(BoomerangProjectile, CL_BOOMERANG_PROJECTILE); |
---|
[3708] | 30 | |
---|
| 31 | /** |
---|
[4836] | 32 | * standard constructor |
---|
[3708] | 33 | */ |
---|
[9217] | 34 | BoomerangProjectile::BoomerangProjectile () : Projectile() |
---|
[3755] | 35 | { |
---|
[9217] | 36 | this->setClassID(CL_BOOMERANG_PROJECTILE, "BoomerangProjectile"); |
---|
[4597] | 37 | |
---|
[9181] | 38 | this->loadModel("models/projectiles/orx-rocket.obj", 2.0); |
---|
[7086] | 39 | this->loadExplosionSound("sound/explosions/explosion_4.wav"); |
---|
[4948] | 40 | |
---|
[7086] | 41 | |
---|
[6431] | 42 | this->setMinEnergy(1); |
---|
[6700] | 43 | this->setHealthMax(10); |
---|
[9223] | 44 | this->lifeSpan = 2.0; |
---|
[7102] | 45 | this->agility = 3.5; |
---|
[9223] | 46 | this->maxVelocity = 150; |
---|
[5443] | 47 | |
---|
[6825] | 48 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[5443] | 49 | this->emitter->setParent(this); |
---|
[5449] | 50 | this->emitter->setSpread(M_PI, M_PI); |
---|
[3755] | 51 | } |
---|
[3708] | 52 | |
---|
| 53 | |
---|
| 54 | /** |
---|
[4836] | 55 | * standard deconstructor |
---|
[3708] | 56 | */ |
---|
[9217] | 57 | BoomerangProjectile::~BoomerangProjectile () |
---|
[3708] | 58 | { |
---|
[5446] | 59 | // delete this->emitter; |
---|
[5444] | 60 | |
---|
[5445] | 61 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[9217] | 62 | if (BoomerangProjectile::trailParticles != NULL && ClassList::getList(CL_BOOMERANG_PROJECTILE)->size() <= 1) |
---|
[5447] | 63 | { |
---|
[9217] | 64 | if (ClassList::exists(BoomerangProjectile::trailParticles, CL_PARTICLE_SYSTEM)) |
---|
| 65 | delete BoomerangProjectile::trailParticles; |
---|
| 66 | BoomerangProjectile::trailParticles = NULL; |
---|
[5447] | 67 | } |
---|
[9217] | 68 | if (BoomerangProjectile::explosionParticles != NULL && ClassList::getList(CL_BOOMERANG_PROJECTILE)->size() <= 1) |
---|
[5444] | 69 | { |
---|
[9217] | 70 | if (ClassList::exists(BoomerangProjectile::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 71 | delete BoomerangProjectile::explosionParticles; |
---|
| 72 | BoomerangProjectile::explosionParticles = NULL; |
---|
[5444] | 73 | } |
---|
[5445] | 74 | |
---|
[3708] | 75 | } |
---|
| 76 | |
---|
[9217] | 77 | SpriteParticles* BoomerangProjectile::trailParticles = NULL; |
---|
| 78 | SpriteParticles* BoomerangProjectile::explosionParticles = NULL; |
---|
[5443] | 79 | |
---|
[5760] | 80 | |
---|
| 81 | |
---|
[9217] | 82 | void BoomerangProjectile::activate() |
---|
[5443] | 83 | { |
---|
[9217] | 84 | if (unlikely(BoomerangProjectile::trailParticles == NULL)) |
---|
[5447] | 85 | { |
---|
[9217] | 86 | BoomerangProjectile::trailParticles = new SpriteParticles(2000); |
---|
| 87 | BoomerangProjectile::trailParticles->setName("BoomerangProjectileTrailParticles"); |
---|
| 88 | BoomerangProjectile::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 89 | BoomerangProjectile::trailParticles->setLifeSpan(1.0, .3); |
---|
| 90 | BoomerangProjectile::trailParticles->setRadius(0.0, .5); |
---|
| 91 | BoomerangProjectile::trailParticles->setRadius(0.2, 4.0); |
---|
| 92 | BoomerangProjectile::trailParticles->setRadius(.5, 1.5); |
---|
| 93 | BoomerangProjectile::trailParticles->setRadius(1.0, 1.5); |
---|
| 94 | BoomerangProjectile::trailParticles->setColor(0.0, 1,0,0,.7); |
---|
| 95 | BoomerangProjectile::trailParticles->setColor(0.2, .8,.8,0,.5); |
---|
| 96 | BoomerangProjectile::trailParticles->setColor(0.5, .8,.8,.8,.8); |
---|
| 97 | BoomerangProjectile::trailParticles->setColor(1.0, .8,.8,.8,.0); |
---|
[5447] | 98 | } |
---|
[9217] | 99 | if (unlikely(BoomerangProjectile::explosionParticles == NULL)) |
---|
[5443] | 100 | { |
---|
[9217] | 101 | BoomerangProjectile::explosionParticles = new SpriteParticles(200); |
---|
| 102 | BoomerangProjectile::explosionParticles->setName("BoomerangProjectileExplosionParticles"); |
---|
| 103 | BoomerangProjectile::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 104 | BoomerangProjectile::explosionParticles->setLifeSpan(.5, .3); |
---|
| 105 | BoomerangProjectile::explosionParticles->setRadius(0.0, 10); |
---|
| 106 | BoomerangProjectile::explosionParticles->setRadius(.5, 15.0); |
---|
| 107 | BoomerangProjectile::explosionParticles->setRadius(1.0, 10.0); |
---|
| 108 | BoomerangProjectile::explosionParticles->setColor(0.0, 0,1,0,1); |
---|
| 109 | BoomerangProjectile::explosionParticles->setColor(0.5, .8,.8,0,.8); |
---|
| 110 | BoomerangProjectile::explosionParticles->setColor(0.8, .8,.8,.3,.8); |
---|
| 111 | BoomerangProjectile::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
[5443] | 112 | } |
---|
| 113 | |
---|
[9217] | 114 | this->emitter->setSystem(BoomerangProjectile::trailParticles); |
---|
[5447] | 115 | |
---|
[5772] | 116 | this->updateNode(0); |
---|
[5472] | 117 | this->emitter->setEmissionRate(45.0); |
---|
[5471] | 118 | this->emitter->setEmissionVelocity(0.0); |
---|
[7072] | 119 | |
---|
| 120 | this->setHealth(10.0* (float)rand()/(float)RAND_MAX); |
---|
[5443] | 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
[9217] | 124 | void BoomerangProjectile::deactivate() |
---|
[5443] | 125 | { |
---|
[6619] | 126 | this->emitter->setSystem(NULL); |
---|
[5447] | 127 | this->lifeCycle = 0.0; |
---|
[5443] | 128 | |
---|
[6142] | 129 | this->toList(OM_DEAD); |
---|
[6056] | 130 | this->removeNode(); |
---|
[9217] | 131 | BoomerangProjectile::fastFactory->kill(this); |
---|
[5443] | 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
[9217] | 135 | void BoomerangProjectile::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5257] | 136 | { |
---|
[6433] | 137 | if (this->hitEntity != entity) |
---|
[9162] | 138 | this->destroy( entity ); |
---|
[5447] | 139 | this->hitEntity = entity; |
---|
[5257] | 140 | } |
---|
[3708] | 141 | |
---|
| 142 | /** |
---|
[4836] | 143 | * signal tick, time dependent things will be handled here |
---|
| 144 | * @param time since last tick |
---|
[3708] | 145 | */ |
---|
[9217] | 146 | void BoomerangProjectile::tick (float time) |
---|
[3708] | 147 | { |
---|
[6162] | 148 | |
---|
[9217] | 149 | Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0); |
---|
[6431] | 150 | |
---|
[9217] | 151 | { |
---|
[6162] | 152 | speed = velocity.len(); |
---|
[9217] | 153 | diffVector = ((targetFarFarAway - this->getAbsCoor()).getNormalized()); |
---|
[5765] | 154 | |
---|
[6162] | 155 | if(velocity.dot(diffVector) != 0) |
---|
[9217] | 156 | { |
---|
| 157 | correctionVector = (( ( diffVector * (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility; |
---|
[6162] | 158 | |
---|
[6426] | 159 | if( (diffVector * (speed * speed/( velocity.dot(diffVector ) ) ) -velocity).len() < agility ) |
---|
[9217] | 160 | velocity = ((diffVector * (speed * speed/( velocity.dot(diffVector ) ) )).getNormalized())*agility; |
---|
[6426] | 161 | else if(velocity.dot(diffVector) > 0) |
---|
[6162] | 162 | velocity += correctionVector; |
---|
| 163 | else if (velocity.dot(diffVector) < 0) |
---|
| 164 | velocity -= correctionVector; |
---|
[9217] | 165 | } |
---|
[6162] | 166 | else |
---|
| 167 | velocity += diffVector * agility; |
---|
| 168 | |
---|
[9217] | 169 | this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0))); |
---|
| 170 | } |
---|
[6162] | 171 | |
---|
| 172 | velocity *= maxVelocity/velocity.len(); |
---|
[4464] | 173 | Vector v = this->velocity * (time); |
---|
[3708] | 174 | this->shiftCoor(v); |
---|
| 175 | |
---|
[6056] | 176 | if(this->tickLifeCycle(time)) |
---|
| 177 | this->deactivate(); |
---|
[3708] | 178 | } |
---|
| 179 | |
---|
| 180 | /** |
---|
[4836] | 181 | * the function gets called, when the projectile is destroyed |
---|
[5765] | 182 | */ |
---|
[9217] | 183 | void BoomerangProjectile::destroy (WorldEntity* killer) |
---|
[5257] | 184 | { |
---|
[9206] | 185 | |
---|
| 186 | printf("THIS SHOULD WORLk\n"); |
---|
| 187 | |
---|
[9162] | 188 | Projectile::destroy( killer ); |
---|
[9217] | 189 | PRINTF(5)("DESTROY BoomerangProjectile\n"); |
---|
[5448] | 190 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[9217] | 191 | this->emitter->setSystem(BoomerangProjectile::explosionParticles); |
---|
[3708] | 192 | |
---|
[5465] | 193 | this->emitter->setEmissionRate(1000.0); |
---|
[5447] | 194 | this->emitter->setEmissionVelocity(50.0); |
---|
[9217] | 195 | // this->deactivate(); |
---|
[3708] | 196 | |
---|
[5257] | 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
[9217] | 200 | void BoomerangProjectile::draw () const |
---|
[3708] | 201 | { |
---|
| 202 | glMatrixMode(GL_MODELVIEW); |
---|
| 203 | glPushMatrix(); |
---|
| 204 | |
---|
[4593] | 205 | float matrix[4][4]; |
---|
[3708] | 206 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 207 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 208 | glMultMatrixf((float*)matrix); |
---|
[3755] | 209 | glScalef(2.0, 2.0, 2.0); |
---|
[5994] | 210 | this->getModel()->draw(); |
---|
[3708] | 211 | |
---|
| 212 | glPopMatrix(); |
---|
[5765] | 213 | |
---|
[3708] | 214 | } |
---|
| 215 | |
---|