| 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: Benjamin Grauer | 
|---|
| 13 | co-programmer: ... | 
|---|
| 14 |  | 
|---|
| 15 | */ | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| 17 |  | 
|---|
| 18 | #include "hyperblast.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "state.h" | 
|---|
| 21 | #include "class_list.h" | 
|---|
| 22 |  | 
|---|
| 23 | #include "box_emitter.h" | 
|---|
| 24 | #include "spark_particles.h" | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | using namespace std; | 
|---|
| 28 |  | 
|---|
| 29 | CREATE_FAST_FACTORY_STATIC(Hyperblast, CL_HYPERBLAST); | 
|---|
| 30 |  | 
|---|
| 31 | /** | 
|---|
| 32 | *  standard constructor | 
|---|
| 33 | */ | 
|---|
| 34 | Hyperblast::Hyperblast () : Projectile() | 
|---|
| 35 | { | 
|---|
| 36 | this->setClassID(CL_HYPERBLAST, "Hyperblast"); | 
|---|
| 37 |  | 
|---|
| 38 | float modelSize = .3; | 
|---|
| 39 | this->loadModel("models/projectiles/hyperblast.obj", 5); | 
|---|
| 40 |  | 
|---|
| 41 | this->setMinEnergy(50); | 
|---|
| 42 | this->setHealthMax(1000); | 
|---|
| 43 | this->lifeSpan = 1; | 
|---|
| 44 | this->size = 4.0; | 
|---|
| 45 |  | 
|---|
| 46 | this->emitter = new BoxEmitter(Vector(400, 2, 2), 100, 5, M_2_PI); | 
|---|
| 47 | this->emitter->setRelCoor(200,0,0); | 
|---|
| 48 | this->emitter->setParent(this); | 
|---|
| 49 | this->emitter->setSpread(M_PI, M_PI); | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | /** | 
|---|
| 54 | *  standard deconstructor | 
|---|
| 55 | */ | 
|---|
| 56 | Hyperblast::~Hyperblast () | 
|---|
| 57 | { | 
|---|
| 58 | /* this is normaly done by World.cc by deleting the ParticleEngine */ | 
|---|
| 59 | if (Hyperblast::explosionParticles != NULL && ClassList::getList(CL_HYPERBLAST)->size() <= 1) | 
|---|
| 60 | { | 
|---|
| 61 | Hyperblast::explosionParticles = NULL; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | SparkParticles* Hyperblast::explosionParticles = NULL; | 
|---|
| 67 |  | 
|---|
| 68 | void Hyperblast::activate() | 
|---|
| 69 | { | 
|---|
| 70 | if (unlikely(Hyperblast::explosionParticles == NULL)) | 
|---|
| 71 | { | 
|---|
| 72 | Hyperblast::explosionParticles = new SparkParticles(2000); | 
|---|
| 73 | Hyperblast::explosionParticles->setName("HyperblastExplosionParticles"); | 
|---|
| 74 | Hyperblast::explosionParticles->setLifeSpan(2, .3); | 
|---|
| 75 | Hyperblast::explosionParticles->setRadius(0.1, .1); | 
|---|
| 76 | Hyperblast::explosionParticles->setRadius(0.2, .2); | 
|---|
| 77 | Hyperblast::explosionParticles->setRadius(1.0, .1); | 
|---|
| 78 | Hyperblast::explosionParticles->setColor(0.0, 1.0, .6, 0 ,1); | 
|---|
| 79 | Hyperblast::explosionParticles->setColor(0.5, .8,.1,0,.6); | 
|---|
| 80 | Hyperblast::explosionParticles->setColor(0.8, .8,.2,.3,.3); | 
|---|
| 81 | Hyperblast::explosionParticles->setColor(1.0, 1,1,1,.0); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | this->emitter->setSystem(Hyperblast::explosionParticles); | 
|---|
| 85 | this->size = 4.0; | 
|---|
| 86 |  | 
|---|
| 87 | Hyperblast::explosionParticles->debug(); | 
|---|
| 88 | this->updateNode(0); | 
|---|
| 89 | this->emitter->setEmissionRate(5000.0); | 
|---|
| 90 | this->emitter->setEmissionVelocity(50.0); | 
|---|
| 91 |  | 
|---|
| 92 | this->setHealth(200); | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|
| 96 | void Hyperblast::deactivate() | 
|---|
| 97 | { | 
|---|
| 98 | this->emitter->setSystem(NULL); | 
|---|
| 99 | this->lifeCycle = 0.0; | 
|---|
| 100 | this->toList(OM_NULL); | 
|---|
| 101 |  | 
|---|
| 102 | //  GarbageCollector::getInstance()->collect(this); | 
|---|
| 103 | this->toList(OM_DEAD); | 
|---|
| 104 | Hyperblast::fastFactory->kill(this); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 |  | 
|---|
| 108 | void Hyperblast::collidesWith(WorldEntity* entity, const Vector& location) | 
|---|
| 109 | { | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | /** | 
|---|
| 113 | *  signal tick, time dependent things will be handled here | 
|---|
| 114 | * @param time since last tick | 
|---|
| 115 | */ | 
|---|
| 116 | void Hyperblast::tick (float dt) | 
|---|
| 117 | { | 
|---|
| 118 | if(this->tickLifeCycle(dt)) | 
|---|
| 119 | this->deactivate(); | 
|---|
| 120 |  | 
|---|
| 121 | this->size *=(1 - (5.0*dt)); | 
|---|
| 122 |  | 
|---|
| 123 | if (this->lifeCycle > .1 && this->emitter->getEmissionRate() > 10.0) | 
|---|
| 124 | this->emitter->setEmissionRate(0.0); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | /** | 
|---|
| 128 | *  the function gets called, when the projectile is destroyed | 
|---|
| 129 | */ | 
|---|
| 130 | void Hyperblast::destroy () | 
|---|
| 131 | { | 
|---|
| 132 | Projectile::destroy(); | 
|---|
| 133 |  | 
|---|
| 134 | PRINTF(5)("DESTROY Hyperblast\n"); | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 |  | 
|---|
| 140 | void Hyperblast::draw () const | 
|---|
| 141 | { | 
|---|
| 142 | if (this->lifeCycle < .1) | 
|---|
| 143 | { | 
|---|
| 144 | glMatrixMode(GL_MODELVIEW); | 
|---|
| 145 | glPushMatrix(); | 
|---|
| 146 |  | 
|---|
| 147 | glTranslatef (this->getAbsCoor ().x, | 
|---|
| 148 | this->getAbsCoor ().y, | 
|---|
| 149 | this->getAbsCoor ().z); | 
|---|
| 150 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); | 
|---|
| 151 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); | 
|---|
| 152 |  | 
|---|
| 153 | //  glScalef(2.0, this->size, this->size); | 
|---|
| 154 | this->getModel()->draw(); | 
|---|
| 155 |  | 
|---|
| 156 | glPopMatrix(); | 
|---|
| 157 | } | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|