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