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