[10044] | 1 | /* |
---|
| 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 |
---|
| 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 19 | |
---|
| 20 | #include "lbolt.h" |
---|
| 21 | |
---|
| 22 | #include "state.h" |
---|
| 23 | #include "model.h" |
---|
| 24 | |
---|
| 25 | #include "particles/dot_emitter.h" |
---|
| 26 | #include "particles/sprite_particles.h" |
---|
| 27 | |
---|
| 28 | #include <cassert> |
---|
| 29 | #include "debug.h" |
---|
| 30 | |
---|
| 31 | #include "static_model.h" |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | #include "class_id_DEPRECATED.h" |
---|
| 35 | ObjectListDefinition(LBolt); |
---|
| 36 | CREATE_FAST_FACTORY_STATIC(LBolt); |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * standard constructor |
---|
| 40 | */ |
---|
| 41 | LBolt::LBolt () : Projectile() |
---|
| 42 | { |
---|
| 43 | this->registerObject(this, LBolt::_objectList); |
---|
| 44 | |
---|
| 45 | this->loadModel("models/projectiles/lbolt.obj"); |
---|
| 46 | |
---|
| 47 | this->setMinEnergy(1); |
---|
| 48 | this->setHealthMax(0); |
---|
| 49 | this->lifeSpan = 5.0; |
---|
| 50 | |
---|
| 51 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
| 52 | this->emitter->setParent(this); |
---|
| 53 | this->emitter->setSpread(M_PI, M_PI); |
---|
| 54 | this->emitter->setEmissionRate(300.0); |
---|
| 55 | this->emitter->setEmissionVelocity(50.0); |
---|
| 56 | |
---|
| 57 | this->angle = 0; |
---|
| 58 | this->rotationSpeed = 130; |
---|
| 59 | /* |
---|
| 60 | this->mat = new Material("lBolt"); |
---|
| 61 | //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
---|
| 62 | this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE); |
---|
| 63 | this->mat->setDiffuse(1,1,1); |
---|
| 64 | this->mat->setDiffuseMap("lbolt.png"); |
---|
| 65 | this->mat->setDiffuseMap("lbolt.png",1); |
---|
| 66 | dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat); |
---|
| 67 | dynamic_cast<StaticModel*>(this->getModel())->finalize();*/ |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * standard deconstructor |
---|
| 73 | */ |
---|
| 74 | LBolt::~LBolt () |
---|
| 75 | { |
---|
| 76 | // delete this->emitter; |
---|
| 77 | |
---|
| 78 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
| 79 | if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1) |
---|
| 80 | { |
---|
| 81 | //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 82 | // delete LBolt::explosionParticles; |
---|
| 83 | PRINTF(1)("Deleting LBolt Particles\n"); |
---|
| 84 | LBolt::explosionParticles = NULL; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | SpriteParticles* LBolt::explosionParticles = NULL; |
---|
| 90 | |
---|
| 91 | void LBolt::activate() |
---|
| 92 | { |
---|
| 93 | if (unlikely(LBolt::explosionParticles == NULL)) |
---|
| 94 | { |
---|
| 95 | LBolt::explosionParticles = new SpriteParticles(1000); |
---|
| 96 | LBolt::explosionParticles->setName("BoltExplosionParticles"); |
---|
| 97 | LBolt::explosionParticles->setLifeSpan(.5, .3); |
---|
| 98 | LBolt::explosionParticles->setRadius(0.0, 10.0); |
---|
| 99 | LBolt::explosionParticles->setRadius(.5, 6.0); |
---|
| 100 | LBolt::explosionParticles->setRadius(1.0, 3.0); |
---|
| 101 | LBolt::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
| 102 | LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 103 | LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | this->setDamage(5); |
---|
| 107 | this->setHealth(0); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | void LBolt::deactivate() |
---|
| 112 | { |
---|
| 113 | assert (LBolt::explosionParticles != NULL); |
---|
| 114 | LBolt::explosionParticles->removeEmitter(this->emitter); |
---|
| 115 | this->lifeCycle = 0.0; |
---|
| 116 | |
---|
| 117 | this->toList(OM_NULL); |
---|
| 118 | this->removeNode(); |
---|
| 119 | LBolt::fastFactory->kill(this); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | void LBolt::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 124 | { |
---|
| 125 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 126 | this->destroy( entity ); |
---|
| 127 | this->hitEntity = entity; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * signal tick, time dependent things will be handled here |
---|
| 132 | * @param dt time since last tick |
---|
| 133 | */ |
---|
| 134 | void LBolt::tick (float dt) |
---|
| 135 | { |
---|
| 136 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 137 | Vector v = this->velocity * dt; |
---|
| 138 | this->shiftCoor(v); |
---|
| 139 | |
---|
| 140 | if (this->tickLifeCycle(dt)) |
---|
| 141 | this->deactivate(); |
---|
| 142 | |
---|
| 143 | angle += rotationSpeed * dt; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | /** |
---|
| 147 | * the function gets called, when the projectile is destroyed |
---|
| 148 | */ |
---|
| 149 | void LBolt::destroy (WorldEntity* killer) |
---|
| 150 | { |
---|
| 151 | Projectile::destroy( killer ); |
---|
| 152 | PRINTF(5)("DESTROY LBolt\n"); |
---|
| 153 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 154 | |
---|
| 155 | this->emitter->setSystem(LBolt::explosionParticles); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | void LBolt::draw () const |
---|
| 160 | { |
---|
| 161 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 162 | glDisable(GL_LIGHTING); |
---|
| 163 | |
---|
| 164 | glMatrixMode(GL_MODELVIEW); |
---|
| 165 | glPushMatrix(); |
---|
| 166 | |
---|
| 167 | float matrix[4][4]; |
---|
| 168 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 169 | glRotatef(angle, 1.0, 0.0, 0.0); |
---|
| 170 | this->getAbsDir().matrix (matrix); |
---|
| 171 | glMultMatrixf((float*)matrix); |
---|
| 172 | this->getModel()->draw(); |
---|
| 173 | glPopMatrix(); |
---|
| 174 | |
---|
| 175 | glPopAttrib(); |
---|
| 176 | } |
---|
| 177 | |
---|