[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 | |
---|
[3709] | 18 | #include "test_bullet.h" |
---|
[3708] | 19 | |
---|
[4947] | 20 | #include "fast_factory.h" |
---|
[3708] | 21 | |
---|
[5443] | 22 | #include "state.h" |
---|
[5444] | 23 | #include "class_list.h" |
---|
[5054] | 24 | |
---|
[5443] | 25 | #include "particle_emitter.h" |
---|
[6621] | 26 | #include "sprite_particles.h" |
---|
[5443] | 27 | |
---|
| 28 | |
---|
[3708] | 29 | using namespace std; |
---|
| 30 | |
---|
[5447] | 31 | CREATE_FAST_FACTORY_STATIC(TestBullet, CL_TEST_BULLET); |
---|
[3708] | 32 | |
---|
| 33 | /** |
---|
[4836] | 34 | * standard constructor |
---|
[3708] | 35 | */ |
---|
[4932] | 36 | TestBullet::TestBullet () : Projectile() |
---|
[3755] | 37 | { |
---|
[4322] | 38 | this->setClassID(CL_TEST_BULLET, "TestBullet"); |
---|
[4597] | 39 | |
---|
[4948] | 40 | float modelSize = .3; |
---|
[5499] | 41 | this->loadModel("models/projectiles/orx-rocket.obj", .3); |
---|
[4948] | 42 | |
---|
[6431] | 43 | this->setMinEnergy(1); |
---|
| 44 | this->setMaxEnergy(10); |
---|
[5451] | 45 | this->lifeSpan = 2; |
---|
[5443] | 46 | |
---|
[5447] | 47 | this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); |
---|
[5443] | 48 | this->emitter->setParent(this); |
---|
[5449] | 49 | this->emitter->setSpread(M_PI, M_PI); |
---|
[3755] | 50 | } |
---|
[3708] | 51 | |
---|
| 52 | |
---|
| 53 | /** |
---|
[4836] | 54 | * standard deconstructor |
---|
[3708] | 55 | */ |
---|
[4593] | 56 | TestBullet::~TestBullet () |
---|
[3708] | 57 | { |
---|
[5446] | 58 | // delete this->emitter; |
---|
[5444] | 59 | |
---|
[5445] | 60 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[5779] | 61 | if (TestBullet::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1) |
---|
[5447] | 62 | { |
---|
| 63 | if (ClassList::exists(TestBullet::trailParticles, CL_PARTICLE_SYSTEM)) |
---|
| 64 | delete TestBullet::trailParticles; |
---|
| 65 | TestBullet::trailParticles = NULL; |
---|
| 66 | } |
---|
[5779] | 67 | if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1) |
---|
[5444] | 68 | { |
---|
[5445] | 69 | if (ClassList::exists(TestBullet::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 70 | delete TestBullet::explosionParticles; |
---|
[5444] | 71 | TestBullet::explosionParticles = NULL; |
---|
| 72 | } |
---|
[5445] | 73 | |
---|
[3708] | 74 | } |
---|
| 75 | |
---|
[5447] | 76 | ParticleSystem* TestBullet::trailParticles = NULL; |
---|
[5443] | 77 | ParticleSystem* TestBullet::explosionParticles = NULL; |
---|
| 78 | |
---|
| 79 | void TestBullet::activate() |
---|
| 80 | { |
---|
[5447] | 81 | if (unlikely(TestBullet::trailParticles == NULL)) |
---|
| 82 | { |
---|
[6621] | 83 | TestBullet::trailParticles = new SpriteParticles(1000); |
---|
[5447] | 84 | TestBullet::trailParticles->setName("TestBulletTrailParticles"); |
---|
| 85 | TestBullet::trailParticles->setLifeSpan(.5, .3); |
---|
| 86 | TestBullet::trailParticles->setRadius(0.0, .5); |
---|
| 87 | TestBullet::trailParticles->setRadius(0.5, 2.0); |
---|
| 88 | TestBullet::trailParticles->setRadius(1.0, 5.0); |
---|
| 89 | TestBullet::trailParticles->setColor(0.0, 1,0,0,.7); |
---|
| 90 | TestBullet::trailParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 91 | TestBullet::trailParticles->setColor(1.0, .7,.7,.7,.0); |
---|
| 92 | } |
---|
[5443] | 93 | if (unlikely(TestBullet::explosionParticles == NULL)) |
---|
| 94 | { |
---|
[6621] | 95 | TestBullet::explosionParticles = new SpriteParticles(1000); |
---|
[5447] | 96 | TestBullet::explosionParticles->setName("TestBulletExplosionParticles"); |
---|
[5446] | 97 | TestBullet::explosionParticles->setLifeSpan(.5, .3); |
---|
[5447] | 98 | TestBullet::explosionParticles->setRadius(0.0, 10); |
---|
| 99 | TestBullet::explosionParticles->setRadius(.5, 20.0); |
---|
| 100 | TestBullet::explosionParticles->setRadius(1.0, 3.0); |
---|
[5448] | 101 | TestBullet::explosionParticles->setColor(0.0, 0,1,0,.9); |
---|
[5443] | 102 | TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
[5447] | 103 | TestBullet::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
[5443] | 104 | } |
---|
| 105 | |
---|
[6619] | 106 | this->emitter->setSystem(TestBullet::trailParticles); |
---|
[5447] | 107 | |
---|
| 108 | this->emitter->setEmissionRate(20.0); |
---|
[5448] | 109 | this->emitter->setEmissionVelocity(3.0); |
---|
[5443] | 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | void TestBullet::deactivate() |
---|
| 114 | { |
---|
[6619] | 115 | this->emitter->setSystem(NULL); |
---|
[5447] | 116 | this->lifeCycle = 0.0; |
---|
[6142] | 117 | this->toList(OM_NULL); |
---|
[5443] | 118 | |
---|
[5447] | 119 | TestBullet::fastFactory->kill(this); |
---|
[5443] | 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
[5257] | 123 | void TestBullet::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 124 | { |
---|
[5447] | 125 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 126 | this->destroy(); |
---|
| 127 | this->hitEntity = entity; |
---|
[5257] | 128 | } |
---|
[3708] | 129 | |
---|
| 130 | /** |
---|
[4836] | 131 | * signal tick, time dependent things will be handled here |
---|
| 132 | * @param time since last tick |
---|
[3708] | 133 | */ |
---|
[4593] | 134 | void TestBullet::tick (float time) |
---|
[3708] | 135 | { |
---|
[4464] | 136 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 137 | Vector v = this->velocity * (time); |
---|
[3708] | 138 | this->shiftCoor(v); |
---|
| 139 | |
---|
[4890] | 140 | this->lifeCycle += time/this->lifeSpan; |
---|
[5447] | 141 | if( this->lifeCycle >= 1.0) |
---|
[3708] | 142 | { |
---|
| 143 | PRINTF(5)("FINALIZE==========================\n"); |
---|
[4890] | 144 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
[3708] | 145 | PRINTF(5)("FINALIZE===========================\n"); |
---|
[5447] | 146 | |
---|
[5443] | 147 | this->deactivate(); |
---|
[3708] | 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /** |
---|
[4836] | 152 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 153 | */ |
---|
[4593] | 154 | void TestBullet::destroy () |
---|
[5257] | 155 | { |
---|
[5448] | 156 | PRINTF(5)("DESTROY TestBullet\n"); |
---|
| 157 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[6619] | 158 | this->emitter->setSystem(TestBullet::explosionParticles); |
---|
[3708] | 159 | |
---|
[5448] | 160 | this->emitter->setEmissionRate(30.0); |
---|
[5447] | 161 | this->emitter->setEmissionVelocity(50.0); |
---|
| 162 | // this->deactivate(); |
---|
[3708] | 163 | |
---|
[5257] | 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
[5500] | 167 | void TestBullet::draw () const |
---|
[3708] | 168 | { |
---|
| 169 | glMatrixMode(GL_MODELVIEW); |
---|
| 170 | glPushMatrix(); |
---|
| 171 | |
---|
[4593] | 172 | float matrix[4][4]; |
---|
[3708] | 173 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 174 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 175 | glMultMatrixf((float*)matrix); |
---|
[3755] | 176 | glScalef(2.0, 2.0, 2.0); |
---|
[5994] | 177 | this->getModel()->draw(); |
---|
[3708] | 178 | |
---|
| 179 | glPopMatrix(); |
---|
| 180 | } |
---|
| 181 | |
---|