1 | #include "heavy_blaster.h" |
---|
2 | #include "world_entities/projectiles/projectile.h" |
---|
3 | |
---|
4 | #include "world_entity.h" |
---|
5 | #include "static_model.h" |
---|
6 | #include "weapon_manager.h" |
---|
7 | #include "util/loading/factory.h" |
---|
8 | |
---|
9 | #include "animation3d.h" |
---|
10 | |
---|
11 | #include "loading/fast_factory.h" |
---|
12 | |
---|
13 | CREATE_FACTORY(HeavyBlaster); |
---|
14 | /** |
---|
15 | * Standard constructor |
---|
16 | */ |
---|
17 | HeavyBlaster::HeavyBlaster () |
---|
18 | : Weapon() |
---|
19 | { |
---|
20 | this->init(); |
---|
21 | } |
---|
22 | |
---|
23 | HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL) |
---|
24 | : Weapon() |
---|
25 | { |
---|
26 | this->init(); |
---|
27 | if (root != NULL) |
---|
28 | this->loadParams(root); |
---|
29 | } |
---|
30 | |
---|
31 | /** |
---|
32 | * Default destructor |
---|
33 | */ |
---|
34 | HeavyBlaster::~HeavyBlaster() |
---|
35 | { |
---|
36 | // model will be deleted from WorldEntity-destructor |
---|
37 | } |
---|
38 | |
---|
39 | void HeavyBlaster::loadParams(const TiXmlElement* root) |
---|
40 | { |
---|
41 | Weapon::loadParams(root); |
---|
42 | } |
---|
43 | |
---|
44 | void HeavyBlaster::init() |
---|
45 | { |
---|
46 | //this->registerObject(this, HeavyBlaster::_objectList); |
---|
47 | |
---|
48 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
49 | |
---|
50 | this->loadModel("models/guns/fragcannon.obj", .4); |
---|
51 | |
---|
52 | |
---|
53 | this->setStateDuration(WS_SHOOTING, 0.5); // 2 Schuss pro Sekunde |
---|
54 | this->setStateDuration(WS_RELOADING, 0); |
---|
55 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
56 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
57 | |
---|
58 | this->setEnergyMax(500); |
---|
59 | this->increaseEnergy(500); |
---|
60 | //this->minCharge = 2; |
---|
61 | |
---|
62 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
63 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
64 | this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav"); |
---|
65 | |
---|
66 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
67 | this->setProjectileTypeC("HBolt"); // FIXME temp project type until the blaste class exist |
---|
68 | this->prepareProjectiles(5); |
---|
69 | |
---|
70 | this->objComp1 = new PNode; |
---|
71 | this->objComp2 = new PNode; |
---|
72 | this->objComp3 = new PNode; |
---|
73 | this->objComp4 = new PNode; |
---|
74 | this->objComp5 = new PNode; |
---|
75 | this->objComp6 = new PNode; |
---|
76 | |
---|
77 | Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING, this->objComp1); |
---|
78 | Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING, this->objComp2); |
---|
79 | Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING, this->objComp3); |
---|
80 | Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING, this->objComp4); |
---|
81 | Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING, this->objComp5); |
---|
82 | Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING, this->objComp6); |
---|
83 | |
---|
84 | animB0Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
85 | animB1Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
86 | animB2Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
87 | animT0Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
88 | animT1Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
89 | animT2Shoot->setInfinity(ANIM_INF_CONSTANT); |
---|
90 | |
---|
91 | animB0Shoot->addKeyFrame(Vector(0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
92 | animB0Shoot->addKeyFrame(Vector(-0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
93 | animB0Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
94 | |
---|
95 | animT0Shoot->addKeyFrame(Vector(0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
96 | animT0Shoot->addKeyFrame(Vector(-0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
97 | animT0Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
98 | |
---|
99 | animB1Shoot->addKeyFrame(Vector(0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
100 | animB1Shoot->addKeyFrame(Vector(-0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
101 | animB1Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
102 | |
---|
103 | animT1Shoot->addKeyFrame(Vector(0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
104 | animT1Shoot->addKeyFrame(Vector(-0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
105 | animT1Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
106 | |
---|
107 | animB2Shoot->addKeyFrame(Vector(0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
108 | animB2Shoot->addKeyFrame(Vector(-0.1, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
109 | animB2Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
110 | |
---|
111 | animT2Shoot->addKeyFrame(Vector(0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
112 | animT2Shoot->addKeyFrame(Vector(-0.14, 0.0, 0.0), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
113 | animT2Shoot->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
114 | |
---|
115 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
116 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
117 | |
---|
118 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
119 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
120 | |
---|
121 | this->setEmissionPoint(3.8, 1.2, 0); |
---|
122 | |
---|
123 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
124 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
125 | |
---|
126 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
127 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | void HeavyBlaster::fire() |
---|
132 | { |
---|
133 | Projectile* pj = this->getProjectile(); |
---|
134 | if (pj == NULL) |
---|
135 | return; |
---|
136 | |
---|
137 | // set the owner |
---|
138 | pj->setOwner(this->getOwner()); |
---|
139 | |
---|
140 | pj->setParent(PNode::getNullParent()); |
---|
141 | |
---|
142 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); |
---|
143 | // pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1)); |
---|
144 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1)); |
---|
145 | |
---|
146 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
147 | pj->setAbsDir(this->getAbsDir()); |
---|
148 | pj->toList(OM_GROUP_01_PROJ); |
---|
149 | pj->activate(); |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * this activates the weapon |
---|
154 | */ |
---|
155 | void HeavyBlaster::activate() |
---|
156 | { |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * this deactivates the weapon |
---|
161 | */ |
---|
162 | void HeavyBlaster::deactivate() |
---|
163 | { |
---|
164 | } |
---|
165 | |
---|
166 | void HeavyBlaster::draw() const |
---|
167 | { |
---|
168 | glMatrixMode(GL_MODELVIEW); |
---|
169 | glPushMatrix(); |
---|
170 | glTranslatef (this->getAbsCoor ().x, |
---|
171 | this->getAbsCoor ().y, |
---|
172 | this->getAbsCoor ().z); |
---|
173 | |
---|
174 | static_cast<StaticModel*>(this->getModel())->draw(6); |
---|
175 | |
---|
176 | glPushMatrix(); |
---|
177 | glTranslatef (this->objComp1->getAbsCoor().x, this->objComp1->getAbsCoor().y, this->objComp1->getAbsCoor().z); |
---|
178 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
179 | static_cast<StaticModel*>(this->getModel())->draw(2); |
---|
180 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
181 | glPopMatrix(); |
---|
182 | /* |
---|
183 | glPushMatrix(); |
---|
184 | glTranslatef (this->objComp2->getAbsCoor().x, this->objComp2->getAbsCoor().y, this->objComp2->getAbsCoor().z); |
---|
185 | static_cast<StaticModel*>(this->getModel())->draw(2); |
---|
186 | glPopMatrix(); |
---|
187 | |
---|
188 | glPushMatrix(); |
---|
189 | glTranslatef (this->objComp3->getAbsCoor().x, this->objComp3->getAbsCoor().y, this->objComp3->getAbsCoor().z); |
---|
190 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
191 | glPopMatrix();*/ |
---|
192 | /* |
---|
193 | glTranslatef (this->objComp4->getAbsCoor().x, this->objComp4->getAbsCoor().y, this->objComp4->getAbsCoor().z); |
---|
194 | static_cast<StaticModel*>(this->getModel())->draw(4); |
---|
195 | static_cast<StaticModel*>(this->getModel())->draw(5); |
---|
196 | static_cast<StaticModel*>(this->getModel())->draw(3); |
---|
197 | glPopMatrix();*/ |
---|
198 | /* |
---|
199 | glPushMatrix(); |
---|
200 | glTranslatef (this->objComp5->getAbsCoor().x, this->objComp5->getAbsCoor().y, this->objComp5->getAbsCoor().z); |
---|
201 | static_cast<StaticModel*>(this->getModel())->draw(5); |
---|
202 | glPopMatrix(); |
---|
203 | |
---|
204 | glPushMatrix(); |
---|
205 | glTranslatef (this->objComp6->getAbsCoor().x, this->objComp6->getAbsCoor().y, this->objComp6->getAbsCoor().z); |
---|
206 | static_cast<StaticModel*>(this->getModel())->draw(3); |
---|
207 | glPopMatrix();*/ |
---|
208 | |
---|
209 | glPopMatrix(); |
---|
210 | } |
---|