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