[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 | |
---|
| 20 | #include "model.h" |
---|
| 21 | #include "vector.h" |
---|
[4941] | 22 | #include "garbage_collector.h" |
---|
[4947] | 23 | #include "fast_factory.h" |
---|
[3708] | 24 | |
---|
[5443] | 25 | #include "state.h" |
---|
| 26 | #include "list.h" |
---|
[5444] | 27 | #include "class_list.h" |
---|
[5054] | 28 | |
---|
[5443] | 29 | #include "particle_engine.h" |
---|
| 30 | #include "particle_emitter.h" |
---|
| 31 | #include "particle_system.h" |
---|
| 32 | |
---|
| 33 | |
---|
[3708] | 34 | using namespace std; |
---|
| 35 | |
---|
[4947] | 36 | CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET); |
---|
[3708] | 37 | |
---|
| 38 | /** |
---|
[4836] | 39 | * standard constructor |
---|
[3708] | 40 | */ |
---|
[4932] | 41 | TestBullet::TestBullet () : Projectile() |
---|
[3755] | 42 | { |
---|
[4322] | 43 | this->setClassID(CL_TEST_BULLET, "TestBullet"); |
---|
[4597] | 44 | |
---|
[4948] | 45 | float modelSize = .3; |
---|
[5057] | 46 | this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3); |
---|
[4948] | 47 | |
---|
| 48 | this->energyMin = 1; |
---|
| 49 | this->energyMax = 10; |
---|
[4969] | 50 | this->remove(); |
---|
[5063] | 51 | this->lifeSpan = 5; |
---|
[5443] | 52 | |
---|
| 53 | this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 0.01); |
---|
| 54 | this->emitter->setParent(this); |
---|
| 55 | this->emitter->setEmissionRate(20); |
---|
| 56 | |
---|
| 57 | this->emitter->setSpread(M_2_PI); |
---|
[3755] | 58 | } |
---|
[3708] | 59 | |
---|
| 60 | |
---|
| 61 | /** |
---|
[4836] | 62 | * standard deconstructor |
---|
[3708] | 63 | */ |
---|
[4593] | 64 | TestBullet::~TestBullet () |
---|
[3708] | 65 | { |
---|
[5443] | 66 | delete this->emitter; |
---|
[5444] | 67 | |
---|
| 68 | /* this is normaly done by World.cc by deleting the ParticleEngine |
---|
| 69 | if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() == 1) |
---|
| 70 | { |
---|
| 71 | delete TestBullet::explosionParticles; |
---|
| 72 | TestBullet::explosionParticles = NULL; |
---|
| 73 | } |
---|
[3708] | 74 | */ |
---|
| 75 | } |
---|
| 76 | |
---|
[5443] | 77 | ParticleSystem* TestBullet::explosionParticles = NULL; |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void TestBullet::activate() |
---|
| 81 | { |
---|
| 82 | State::getWorldEntityList()->add(this); |
---|
| 83 | if (unlikely(TestBullet::explosionParticles == NULL)) |
---|
| 84 | { |
---|
| 85 | TestBullet::explosionParticles = new ParticleSystem(10000, PARTICLE_SPRITE); |
---|
| 86 | TestBullet::explosionParticles->setLifeSpan(.5); |
---|
| 87 | TestBullet::explosionParticles->setRadius(0.0, .5); |
---|
| 88 | TestBullet::explosionParticles->setRadius(0.5, 2.0); |
---|
| 89 | TestBullet::explosionParticles->setRadius(0.0, 0.0); |
---|
| 90 | TestBullet::explosionParticles->setColor(0.0, 1,0,0,.7); |
---|
| 91 | TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
| 92 | TestBullet::explosionParticles->setColor(1.0, .5,.5,.5,.0); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | void TestBullet::deactivate() |
---|
| 100 | { |
---|
| 101 | ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::explosionParticles); |
---|
| 102 | |
---|
| 103 | GarbageCollector::getInstance()->collect(this); |
---|
| 104 | this->lifeCycle = 0.0; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
[5257] | 108 | void TestBullet::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 109 | { |
---|
[5443] | 110 | |
---|
[5257] | 111 | } |
---|
[3708] | 112 | |
---|
| 113 | /** |
---|
[4836] | 114 | * signal tick, time dependent things will be handled here |
---|
| 115 | * @param time since last tick |
---|
[3708] | 116 | */ |
---|
[4593] | 117 | void TestBullet::tick (float time) |
---|
[3708] | 118 | { |
---|
[4464] | 119 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 120 | Vector v = this->velocity * (time); |
---|
[3708] | 121 | this->shiftCoor(v); |
---|
| 122 | |
---|
[4890] | 123 | this->lifeCycle += time/this->lifeSpan; |
---|
| 124 | if( this->lifeCycle >= 1) |
---|
[3708] | 125 | { |
---|
| 126 | PRINTF(5)("FINALIZE==========================\n"); |
---|
[4890] | 127 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
[3708] | 128 | PRINTF(5)("FINALIZE===========================\n"); |
---|
[4941] | 129 | // this->finalize(); |
---|
[5443] | 130 | this->deactivate(); |
---|
[3708] | 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
[4836] | 135 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 136 | */ |
---|
[4593] | 137 | void TestBullet::destroy () |
---|
[5257] | 138 | { |
---|
[5443] | 139 | this->deactivate(); |
---|
[3708] | 140 | |
---|
| 141 | |
---|
[5443] | 142 | GarbageCollector::getInstance()->collect(this); |
---|
| 143 | |
---|
[5257] | 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
[4593] | 147 | void TestBullet::draw () |
---|
[3708] | 148 | { |
---|
| 149 | glMatrixMode(GL_MODELVIEW); |
---|
| 150 | glPushMatrix(); |
---|
| 151 | |
---|
[4593] | 152 | float matrix[4][4]; |
---|
[3708] | 153 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 154 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 155 | glMultMatrixf((float*)matrix); |
---|
[3755] | 156 | glScalef(2.0, 2.0, 2.0); |
---|
[3708] | 157 | this->model->draw(); |
---|
| 158 | |
---|
| 159 | glPopMatrix(); |
---|
| 160 | } |
---|
| 161 | |
---|