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