Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/medium_blaster.cc @ 10368

Last change on this file since 10368 was 10368, checked in by patrick, 17 years ago

merged the branche playability into the trunk

File size: 4.8 KB
RevLine 
[9972]1#include "medium_blaster.h"
[9975]2#include "world_entities/projectiles/projectile.h"
[9972]3
[9975]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
[10366]13//
[10117]14//ObjectListDefinition(MediumBlaster);
[9975]15CREATE_FACTORY(MediumBlaster);
16/**
17 * Standard constructor
18 */
19MediumBlaster::MediumBlaster ()
20 : Weapon()
21{
22    this->init();
23}
24
[9972]25MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL)
26 : Weapon()
[9975]27{
[9972]28    this->init();
29    if (root != NULL)
30      this->loadParams(root);
[9975]31}
[9972]32
33/**
34 * Default destructor
35 */
36MediumBlaster::~MediumBlaster()
[9975]37{
[9972]38      // model will be deleted from WorldEntity-destructor
[10286]39  for (int i = 0; i < this->getBarrels(); i++)
40  {
41   delete [] this->shootAnim[i];
42  }
43  delete [] this->shootAnim;
[9975]44}
[9972]45
[9975]46void MediumBlaster::loadParams(const TiXmlElement* root)
47{
48  Weapon::loadParams(root);
49}
[9972]50
[9975]51void MediumBlaster::init()
52{
[10286]53  this->loadModel("models/guns/blaster.obj", .33);
[9975]54
[10036]55  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
[9998]56
[9975]57  this->setStateDuration(WS_RELOADING, 0);
[10132]58  this->setStateDuration(WS_ACTIVATING, .5); //.5);
59  this->setStateDuration(WS_DEACTIVATING, 1); // 1);
[9975]60
[9998]61  this->setEnergyMax(500);
62  this->increaseEnergy(500);
[9975]63  //this->minCharge = 2;
64
65  this->setActionSound(WA_SHOOT, "sound/laser.wav");
66  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
67  this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav");
68
69  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[9998]70  this->setProjectileTypeC("MBolt");   // FIXME temp project type until the blaste class exist
[10117]71  this->prepareProjectiles(100);
[9975]72
[10286]73
74  this->setBarrels(1);
75  this->setSegs(2);
76  this->activeBarrel = 0;
77
78  this->objComp = new PNode**[this->getBarrels()];
79  this->shootAnim = new Animation3D**[this->getBarrels()];
80  for (int i = 0; i < this->getBarrels(); i++)
81  {
82    this->objComp[i] = new PNode* [this->getSegs()];
83    this->shootAnim[i] = new Animation3D* [this->getSegs()];
84    for(int j = 0; j < this->getSegs(); j++)
85    {
86      this->objComp[i][j] = new PNode;
87      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
88      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
89    }
90  }
91
92  for (int i = 0; i < this->getBarrels(); i++){
93    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
94    this->shootAnim[i][0]->addKeyFrame(Vector(-0.333, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
95    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
96
97    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
98    this->shootAnim[i][1]->addKeyFrame(Vector(.166, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
99    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
100  }
101
[9975]102  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
103  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
104
105  animation2->setInfinity(ANIM_INF_CONSTANT);
106  animation3->setInfinity(ANIM_INF_CONSTANT);
107
108
[10286]109  this->setEmissionPoint(1.3, 0, 0);
110
[9975]111  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
112  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
113
114  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
115  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
116}
117
118
119void MediumBlaster::fire()
120{
121  Projectile* pj =  this->getProjectile();
122  if (pj == NULL)
123    return;
124
125  // set the owner
126  pj->setOwner(this->getOwner());
127
128  pj->setParent(PNode::getNullParent());
129
[10098]130  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
[9975]131
132  pj->setAbsCoor(this->getEmissionPoint());
133  pj->setAbsDir(this->getAbsDir());
134  pj->activate();
[10286]135
136  for (int i = 0; i < this->getSegs(); i++)
137    this->shootAnim[this->activeBarrel][i]->replay();
[9975]138}
139
140/**
141 *  this activates the weapon
142*/
143void MediumBlaster::activate()
144{
145}
146
147/**
148 *  this deactivates the weapon
149*/
150void MediumBlaster::deactivate()
151{
152}
153
154void MediumBlaster::draw() const
155{
[10286]156  glMatrixMode(GL_MODELVIEW);
157  glPushMatrix();
[10289]158  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
[10286]159
160  static_cast<StaticModel*>(this->getModel())->draw(2);
161
162  glPushMatrix();
163    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
164    static_cast<StaticModel*>(this->getModel())->draw(1);
165  glPopMatrix();
166
167  glPushMatrix();
[10289]168    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
169    static_cast<StaticModel*>(this->getModel())->draw(0);
[10286]170  glPopMatrix();
171
172  glPopMatrix();
[9975]173}
Note: See TracBrowser for help on using the repository browser.