1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004-2006 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: Marc Schaerrer, Nicolas Schlumberger |
---|
13 | co-programmer: |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #include "heavy_blaster.h" |
---|
18 | #include "world_entities/projectiles/projectile.h" |
---|
19 | |
---|
20 | #include "world_entity.h" |
---|
21 | #include "static_model.h" |
---|
22 | #include "weapon_manager.h" |
---|
23 | #include "util/loading/factory.h" |
---|
24 | |
---|
25 | #include "animation3d.h" |
---|
26 | |
---|
27 | #include "loading/fast_factory.h" |
---|
28 | |
---|
29 | #include "elements/glgui_energywidgetvertical.h" |
---|
30 | |
---|
31 | CREATE_FACTORY(HeavyBlaster); |
---|
32 | |
---|
33 | |
---|
34 | /** |
---|
35 | * Standard constructor |
---|
36 | */ |
---|
37 | HeavyBlaster::HeavyBlaster (int leftRight = W_RIGHT) |
---|
38 | : Weapon() |
---|
39 | { |
---|
40 | |
---|
41 | this->init(leftRight); |
---|
42 | } |
---|
43 | |
---|
44 | HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL) |
---|
45 | : Weapon() |
---|
46 | { |
---|
47 | // this->registerObject(this, HeavyBlaster::_objectList); |
---|
48 | |
---|
49 | // TODO add leftRight to params |
---|
50 | this->init(0); |
---|
51 | if (root != NULL) |
---|
52 | this->loadParams(root); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Default destructor |
---|
57 | */ |
---|
58 | HeavyBlaster::~HeavyBlaster() |
---|
59 | { |
---|
60 | } |
---|
61 | |
---|
62 | void HeavyBlaster::loadParams(const TiXmlElement* root) |
---|
63 | { |
---|
64 | Weapon::loadParams(root); |
---|
65 | } |
---|
66 | |
---|
67 | void HeavyBlaster::init(int leftRight) |
---|
68 | { |
---|
69 | |
---|
70 | this->leftRight = leftRight; |
---|
71 | |
---|
72 | this->loadModel("models/guns/frag_cannon2.obj", .4); |
---|
73 | |
---|
74 | |
---|
75 | this->setStateDuration(WS_SHOOTING, 0.5); // 2 Schuss pro Sekunde |
---|
76 | this->setStateDuration(WS_RELOADING, 0); |
---|
77 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
78 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
79 | |
---|
80 | this->setEnergyMax(500); |
---|
81 | this->increaseEnergy(500); |
---|
82 | |
---|
83 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
84 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
85 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
86 | |
---|
87 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
88 | this->setProjectileTypeC("HBolt"); |
---|
89 | this->prepareProjectiles(5); |
---|
90 | |
---|
91 | this->setBarrels(3); |
---|
92 | this->setSegs(2); |
---|
93 | |
---|
94 | |
---|
95 | if (this->leftRight == W_LEFT) |
---|
96 | { |
---|
97 | this->setEmissionPoint(Vector(1.1, 0.14, -.06), 0); |
---|
98 | this->setEmissionPoint(Vector(1.1, -.06, -.14), 1); |
---|
99 | this->setEmissionPoint(Vector(1.1, 0.06, 0.14), 2); |
---|
100 | } |
---|
101 | else { |
---|
102 | this->setEmissionPoint(Vector(1.1, 0.14, 0.06), 0); |
---|
103 | this->setEmissionPoint(Vector(1.1, -.06, 0.14), 1); |
---|
104 | this->setEmissionPoint(Vector(1.1, 0.06, -.14), 2); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | for (int i = 0; i < this->getBarrels(); i++){ |
---|
109 | this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL); |
---|
110 | this->getShootAnim(i, 0)->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL); |
---|
111 | this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
112 | |
---|
113 | this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
114 | this->getShootAnim(i, 1)->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL); |
---|
115 | this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
116 | } |
---|
117 | |
---|
118 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
119 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
120 | |
---|
121 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
122 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
123 | |
---|
124 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
125 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
126 | |
---|
127 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
128 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | void HeavyBlaster::fire() |
---|
133 | { |
---|
134 | Projectile* pj = this->getProjectile(); |
---|
135 | if (pj == NULL) |
---|
136 | return; |
---|
137 | |
---|
138 | // set the owner |
---|
139 | pj->setOwner(this->getOwner()); |
---|
140 | pj->setParent(PNode::getNullParent()); |
---|
141 | |
---|
142 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1)); |
---|
143 | |
---|
144 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
145 | pj->setAbsDir(this->getAbsDir()); |
---|
146 | pj->activate(); |
---|
147 | |
---|
148 | // initiate animation |
---|
149 | for (int i = 0; i < this->getSegs(); i++) |
---|
150 | this->getShootAnim(this->getActiveBarrel(), i)->replay(); // FIXME needs clean up |
---|
151 | |
---|
152 | this->cycleBarrel(); |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * this activates the weapon |
---|
157 | */ |
---|
158 | void HeavyBlaster::activate() |
---|
159 | { |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | * this deactivates the weapon |
---|
164 | */ |
---|
165 | void HeavyBlaster::deactivate() |
---|
166 | { |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | void HeavyBlaster::draw() const |
---|
171 | { |
---|
172 | glMatrixMode(GL_MODELVIEW); |
---|
173 | glPushMatrix(); |
---|
174 | glTranslatef (this->getAbsCoor ().x, |
---|
175 | this->getAbsCoor ().y, |
---|
176 | this->getAbsCoor ().z); |
---|
177 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
178 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
179 | |
---|
180 | if (this->leftRight == W_LEFT) |
---|
181 | glScalef(1.0, 1.0, -1.0); //FIXME check weather this causes a slowdown... |
---|
182 | |
---|
183 | static_cast<StaticModel*>(this->getModel())->draw(6); |
---|
184 | |
---|
185 | glPushMatrix(); |
---|
186 | glTranslatef (this->getObjCompx(0,0), this->getObjCompy(0,0), this->getObjCompz(0,0)); |
---|
187 | static_cast<StaticModel*>(this->getModel())->draw(2); |
---|
188 | glPopMatrix(); |
---|
189 | |
---|
190 | glPushMatrix(); |
---|
191 | glTranslatef (this->getObjCompx(1,0), this->getObjCompy(1,0), this->getObjCompz(1,0)); |
---|
192 | static_cast<StaticModel*>(this->getModel())->draw(3); |
---|
193 | glPopMatrix(); |
---|
194 | |
---|
195 | glPushMatrix(); |
---|
196 | glTranslatef (this->getObjCompx(2,0), this->getObjCompy(2,0), this->getObjCompz(2,0)); |
---|
197 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
198 | glPopMatrix(); |
---|
199 | |
---|
200 | glPushMatrix(); |
---|
201 | glTranslatef (this->getObjCompx(0,1), this->getObjCompy(0,1), this->getObjCompz(0,1)); |
---|
202 | static_cast<StaticModel*>(this->getModel())->draw(4); |
---|
203 | glPopMatrix(); |
---|
204 | |
---|
205 | glPushMatrix(); |
---|
206 | glTranslatef (this->getObjCompx(1,1), this->getObjCompy(1,1), this->getObjCompz(1,1)); |
---|
207 | static_cast<StaticModel*>(this->getModel())->draw(5); |
---|
208 | glPopMatrix(); |
---|
209 | |
---|
210 | glPushMatrix(); |
---|
211 | glTranslatef (this->getObjCompx(2,1), this->getObjCompy(2,1), this->getObjCompz(2,1)); |
---|
212 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
213 | glPopMatrix(); |
---|
214 | |
---|
215 | glPopMatrix(); |
---|
216 | } |
---|
217 | |
---|
218 | void HeavyBlaster::tick(float dt) |
---|
219 | { |
---|
220 | if (!Weapon::tickW(dt)) |
---|
221 | return; |
---|
222 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
223 | { |
---|
224 | this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png"); |
---|
225 | this->setEnergyWidgetInitialized(true); |
---|
226 | } |
---|
227 | } |
---|