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