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 "rail_projectile.h" |
---|
19 | |
---|
20 | #include "state.h" |
---|
21 | #include "model.h" |
---|
22 | |
---|
23 | #include "particles/dot_emitter.h" |
---|
24 | #include "particles/sprite_particles.h" |
---|
25 | |
---|
26 | #include <cassert> |
---|
27 | #include "debug.h" |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | ObjectListDefinition(RailProjectile); |
---|
32 | CREATE_FAST_FACTORY_STATIC(RailProjectile); |
---|
33 | |
---|
34 | /** |
---|
35 | * standard constructor |
---|
36 | */ |
---|
37 | RailProjectile::RailProjectile () : Projectile() |
---|
38 | { |
---|
39 | this->registerObject(this, RailProjectile::_objectList); |
---|
40 | |
---|
41 | this->loadModel("models/projectiles/laser.obj", 1); |
---|
42 | |
---|
43 | this->setMinEnergy(10); |
---|
44 | this->setHealthMax(10); |
---|
45 | this->lifeSpan = .5f; |
---|
46 | |
---|
47 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
48 | this->emitter->setParent(this); |
---|
49 | this->emitter->setSpread(M_PI, M_PI); |
---|
50 | this->emitter->setEmissionRate(300.0); |
---|
51 | this->emitter->setEmissionVelocity(50.0); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * standard deconstructor |
---|
57 | */ |
---|
58 | RailProjectile::~RailProjectile () |
---|
59 | { |
---|
60 | // delete this->emitter; |
---|
61 | |
---|
62 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
63 | if (RailProjectile::explosionParticles != NULL && RailProjectile::objectList().size() <= 1) |
---|
64 | { |
---|
65 | //if (ClassList::exists(RailProjectile::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
66 | // delete RailProjectile::explosionParticles; |
---|
67 | PRINTF(1)("Deleting RailProjectile Particles\n"); |
---|
68 | RailProjectile::explosionParticles = NULL; |
---|
69 | } |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | SpriteParticles* RailProjectile::explosionParticles = NULL; |
---|
74 | |
---|
75 | void RailProjectile::activate() |
---|
76 | { |
---|
77 | if (unlikely(RailProjectile::explosionParticles == NULL)) |
---|
78 | { |
---|
79 | RailProjectile::explosionParticles = new SpriteParticles(1000); |
---|
80 | RailProjectile::explosionParticles->setName("RailProjectileExplosionParticles"); |
---|
81 | RailProjectile::explosionParticles->setLifeSpan(.5, .3); |
---|
82 | RailProjectile::explosionParticles->setRadius(0.0, 10.0); |
---|
83 | RailProjectile::explosionParticles->setRadius(.5, 6.0); |
---|
84 | RailProjectile::explosionParticles->setRadius(1.0, 3.0); |
---|
85 | RailProjectile::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
86 | RailProjectile::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
87 | RailProjectile::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
88 | } |
---|
89 | |
---|
90 | this->setHealth(10); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | void RailProjectile::deactivate() |
---|
95 | { |
---|
96 | assert (RailProjectile::explosionParticles != NULL); |
---|
97 | RailProjectile::explosionParticles->removeEmitter(this->emitter); |
---|
98 | this->lifeCycle = 0.0; |
---|
99 | |
---|
100 | this->toList(OM_NULL); |
---|
101 | this->removeNode(); |
---|
102 | RailProjectile::fastFactory->kill(this); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | void RailProjectile::collidesWith(WorldEntity* entity, const Vector& location) |
---|
107 | { |
---|
108 | if (this->hitEntity != entity && entity->isA( "NPC" )) |
---|
109 | this->destroy( entity ); |
---|
110 | this->hitEntity = entity; |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | * signal tick, time dependent things will be handled here |
---|
115 | * @param dt time since last tick |
---|
116 | */ |
---|
117 | void RailProjectile::tick (float dt) |
---|
118 | { |
---|
119 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
120 | Vector v = this->velocity * dt; |
---|
121 | this->shiftCoor(v); |
---|
122 | |
---|
123 | if (this->tickLifeCycle(dt)) |
---|
124 | this->deactivate(); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * the function gets called, when the projectile is destroyed |
---|
129 | */ |
---|
130 | void RailProjectile::destroy (WorldEntity* killer) |
---|
131 | { |
---|
132 | Projectile::destroy( killer ); |
---|
133 | PRINTF(5)("DESTROY RailProjectile\n"); |
---|
134 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
135 | |
---|
136 | this->emitter->setSystem(RailProjectile::explosionParticles); |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | void RailProjectile::draw () const |
---|
141 | { |
---|
142 | glPushAttrib(GL_ENABLE_BIT); |
---|
143 | glDisable(GL_LIGHTING); |
---|
144 | |
---|
145 | WorldEntity::draw(); |
---|
146 | /* glMatrixMode(GL_MODELVIEW); |
---|
147 | glPushMatrix(); |
---|
148 | |
---|
149 | float matrix[4][4]; |
---|
150 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
151 | this->getAbsDir().matrix (matrix); |
---|
152 | glMultMatrixf((float*)matrix); |
---|
153 | glScalef(2.0, 2.0, 2.0); |
---|
154 | this->getModel()->draw(); |
---|
155 | glPopMatrix();*/ |
---|
156 | |
---|
157 | glPopAttrib(); |
---|
158 | } |
---|
159 | |
---|