1 | /* |
---|
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 |
---|
13 | co-programmer: Benjamin Grauer |
---|
14 | |
---|
15 | */ |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
17 | |
---|
18 | #include "test_bullet.h" |
---|
19 | |
---|
20 | #include "model.h" |
---|
21 | #include "vector.h" |
---|
22 | #include "garbage_collector.h" |
---|
23 | #include "fast_factory.h" |
---|
24 | |
---|
25 | #include "state.h" |
---|
26 | #include "list.h" |
---|
27 | |
---|
28 | #include "particle_engine.h" |
---|
29 | #include "particle_emitter.h" |
---|
30 | #include "particle_system.h" |
---|
31 | |
---|
32 | |
---|
33 | using namespace std; |
---|
34 | |
---|
35 | CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET); |
---|
36 | |
---|
37 | /** |
---|
38 | * standard constructor |
---|
39 | */ |
---|
40 | TestBullet::TestBullet () : Projectile() |
---|
41 | { |
---|
42 | this->setClassID(CL_TEST_BULLET, "TestBullet"); |
---|
43 | |
---|
44 | float modelSize = .3; |
---|
45 | this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3); |
---|
46 | |
---|
47 | this->energyMin = 1; |
---|
48 | this->energyMax = 10; |
---|
49 | this->remove(); |
---|
50 | this->lifeSpan = 5; |
---|
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); |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | /** |
---|
61 | * standard deconstructor |
---|
62 | */ |
---|
63 | TestBullet::~TestBullet () |
---|
64 | { |
---|
65 | delete this->emitter; |
---|
66 | /* |
---|
67 | do not delete the test projectModel, since it is pnode |
---|
68 | and will be cleaned out by world |
---|
69 | */ |
---|
70 | //delete this->projectileModel; |
---|
71 | } |
---|
72 | |
---|
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 | |
---|
104 | void TestBullet::collidesWith(WorldEntity* entity, const Vector& location) |
---|
105 | { |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * signal tick, time dependent things will be handled here |
---|
111 | * @param time since last tick |
---|
112 | */ |
---|
113 | void TestBullet::tick (float time) |
---|
114 | { |
---|
115 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
116 | Vector v = this->velocity * (time); |
---|
117 | this->shiftCoor(v); |
---|
118 | |
---|
119 | this->lifeCycle += time/this->lifeSpan; |
---|
120 | if( this->lifeCycle >= 1) |
---|
121 | { |
---|
122 | PRINTF(5)("FINALIZE==========================\n"); |
---|
123 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
124 | PRINTF(5)("FINALIZE===========================\n"); |
---|
125 | // this->finalize(); |
---|
126 | this->deactivate(); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * the function gets called, when the projectile is destroyed |
---|
132 | */ |
---|
133 | void TestBullet::destroy () |
---|
134 | { |
---|
135 | this->deactivate(); |
---|
136 | |
---|
137 | |
---|
138 | GarbageCollector::getInstance()->collect(this); |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | void TestBullet::draw () |
---|
144 | { |
---|
145 | glMatrixMode(GL_MODELVIEW); |
---|
146 | glPushMatrix(); |
---|
147 | |
---|
148 | float matrix[4][4]; |
---|
149 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
150 | this->getAbsDir().matrix (matrix); |
---|
151 | glMultMatrixf((float*)matrix); |
---|
152 | glScalef(2.0, 2.0, 2.0); |
---|
153 | this->model->draw(); |
---|
154 | |
---|
155 | glPopMatrix(); |
---|
156 | } |
---|
157 | |
---|