[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 "laser.h" |
---|
[3708] | 19 | |
---|
[5443] | 20 | #include "state.h" |
---|
[5444] | 21 | #include "class_list.h" |
---|
[5511] | 22 | #include "model.h" |
---|
[5054] | 23 | |
---|
[6822] | 24 | #include "dot_emitter.h" |
---|
[6621] | 25 | #include "sprite_particles.h" |
---|
[5443] | 26 | |
---|
[6753] | 27 | #include <cassert> |
---|
[8362] | 28 | #include "debug.h" |
---|
[5443] | 29 | |
---|
[3708] | 30 | using namespace std; |
---|
| 31 | |
---|
[5456] | 32 | CREATE_FAST_FACTORY_STATIC(Laser, CL_LASER); |
---|
[3708] | 33 | |
---|
| 34 | /** |
---|
[4836] | 35 | * standard constructor |
---|
[3708] | 36 | */ |
---|
[5456] | 37 | Laser::Laser () : Projectile() |
---|
[3755] | 38 | { |
---|
[5512] | 39 | this->setClassID(CL_LASER, "Laser"); |
---|
[4597] | 40 | |
---|
[5687] | 41 | this->loadModel("models/projectiles/laser.obj"); |
---|
[4948] | 42 | |
---|
[7077] | 43 | this->setMinEnergy(10); |
---|
[6700] | 44 | this->setHealthMax(10); |
---|
[6162] | 45 | this->lifeSpan = 5.0; |
---|
[5443] | 46 | |
---|
[6825] | 47 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[5443] | 48 | this->emitter->setParent(this); |
---|
[5449] | 49 | this->emitter->setSpread(M_PI, M_PI); |
---|
[5465] | 50 | this->emitter->setEmissionRate(300.0); |
---|
[5456] | 51 | this->emitter->setEmissionVelocity(50.0); |
---|
[3755] | 52 | } |
---|
[3708] | 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
[4836] | 56 | * standard deconstructor |
---|
[3708] | 57 | */ |
---|
[5456] | 58 | Laser::~Laser () |
---|
[3708] | 59 | { |
---|
[5446] | 60 | // delete this->emitter; |
---|
[5444] | 61 | |
---|
[5445] | 62 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[5779] | 63 | if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 1) |
---|
[5447] | 64 | { |
---|
[5512] | 65 | //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 66 | // delete Laser::explosionParticles; |
---|
| 67 | PRINTF(1)("Deleting Laser Particles\n"); |
---|
[5456] | 68 | Laser::explosionParticles = NULL; |
---|
[5447] | 69 | } |
---|
[5445] | 70 | |
---|
[3708] | 71 | } |
---|
| 72 | |
---|
[6622] | 73 | SpriteParticles* Laser::explosionParticles = NULL; |
---|
[5443] | 74 | |
---|
[5456] | 75 | void Laser::activate() |
---|
[5443] | 76 | { |
---|
[5456] | 77 | if (unlikely(Laser::explosionParticles == NULL)) |
---|
[5447] | 78 | { |
---|
[6621] | 79 | Laser::explosionParticles = new SpriteParticles(1000); |
---|
[5456] | 80 | Laser::explosionParticles->setName("LaserExplosionParticles"); |
---|
| 81 | Laser::explosionParticles->setLifeSpan(.5, .3); |
---|
[5750] | 82 | Laser::explosionParticles->setRadius(0.0, 10.0); |
---|
[5465] | 83 | Laser::explosionParticles->setRadius(.5, 6.0); |
---|
[5456] | 84 | Laser::explosionParticles->setRadius(1.0, 3.0); |
---|
[5457] | 85 | Laser::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
[5456] | 86 | Laser::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
[5457] | 87 | Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
[5447] | 88 | } |
---|
[7077] | 89 | |
---|
| 90 | this->setHealth(10); |
---|
[5443] | 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
[5456] | 94 | void Laser::deactivate() |
---|
[5443] | 95 | { |
---|
[6619] | 96 | assert (Laser::explosionParticles != NULL); |
---|
| 97 | Laser::explosionParticles->removeEmitter(this->emitter); |
---|
[5447] | 98 | this->lifeCycle = 0.0; |
---|
[5443] | 99 | |
---|
[6142] | 100 | this->toList(OM_NULL); |
---|
[6056] | 101 | this->removeNode(); |
---|
[5456] | 102 | Laser::fastFactory->kill(this); |
---|
[5443] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
[5456] | 106 | void Laser::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5257] | 107 | { |
---|
[5447] | 108 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 109 | this->destroy(); |
---|
| 110 | this->hitEntity = entity; |
---|
[5257] | 111 | } |
---|
[3708] | 112 | |
---|
| 113 | /** |
---|
[4836] | 114 | * signal tick, time dependent things will be handled here |
---|
[6056] | 115 | * @param dt time since last tick |
---|
[3708] | 116 | */ |
---|
[6056] | 117 | void Laser::tick (float dt) |
---|
[3708] | 118 | { |
---|
[4464] | 119 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
[6056] | 120 | Vector v = this->velocity * dt; |
---|
[3708] | 121 | this->shiftCoor(v); |
---|
| 122 | |
---|
[6056] | 123 | if (this->tickLifeCycle(dt)) |
---|
| 124 | this->deactivate(); |
---|
[3708] | 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
[4836] | 128 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 129 | */ |
---|
[5456] | 130 | void Laser::destroy () |
---|
[5257] | 131 | { |
---|
[7086] | 132 | Projectile::destroy(); |
---|
[5456] | 133 | PRINTF(5)("DESTROY Laser\n"); |
---|
[5448] | 134 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[6619] | 135 | |
---|
| 136 | this->emitter->setSystem(Laser::explosionParticles); |
---|
[5257] | 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[5500] | 140 | void Laser::draw () const |
---|
[3708] | 141 | { |
---|
[5457] | 142 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 143 | glDisable(GL_LIGHTING); |
---|
[3708] | 144 | |
---|
[9061] | 145 | WorldEntity::draw(); |
---|
| 146 | /* glMatrixMode(GL_MODELVIEW); |
---|
| 147 | glPushMatrix(); |
---|
| 148 | |
---|
[4593] | 149 | float matrix[4][4]; |
---|
[3708] | 150 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 151 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 152 | glMultMatrixf((float*)matrix); |
---|
[3755] | 153 | glScalef(2.0, 2.0, 2.0); |
---|
[5994] | 154 | this->getModel()->draw(); |
---|
[9061] | 155 | glPopMatrix();*/ |
---|
| 156 | |
---|
[5457] | 157 | glPopAttrib(); |
---|
[3708] | 158 | } |
---|
| 159 | |
---|