Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10621 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 5.7 KB
Line 
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 "medium_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//
32//ObjectListDefinition(MediumBlaster);
33CREATE_FACTORY(MediumBlaster);
34/**
35 * Standard constructor
36 */
37MediumBlaster::MediumBlaster ()
38 : Weapon()
39{
40    this->init();
41}
42
43MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL)
44 : Weapon()
45{
46    this->init();
47    if (root != NULL)
48      this->loadParams(root);
49}
50
51/**
52 * Default destructor
53 */
54MediumBlaster::~MediumBlaster()
55{
56      // model will be deleted from WorldEntity-destructor
57  for (int i = 0; i < this->getBarrels(); i++)
58  {
59   delete [] this->shootAnim[i];
60  }
61  delete [] this->shootAnim;
62}
63
64void MediumBlaster::loadParams(const TiXmlElement* root)
65{
66  Weapon::loadParams(root);
67}
68
69void MediumBlaster::init()
70{
71  this->loadModel("models/guns/blaster.obj", .33);
72
73  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
74
75  this->setStateDuration(WS_RELOADING, 0);
76  this->setStateDuration(WS_ACTIVATING, .5); //.5);
77  this->setStateDuration(WS_DEACTIVATING, 1); // 1);
78
79  this->setEnergyMax(500);
80  this->increaseEnergy(500);
81  //this->minCharge = 2;
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("MBolt");   // FIXME temp project type until the blaste class exist
89  this->prepareProjectiles(100);
90
91
92  this->setBarrels(1);
93  this->setSegs(2);
94  this->activeBarrel = 0;
95
96  this->objComp = new PNode**[this->getBarrels()];
97  this->shootAnim = new Animation3D**[this->getBarrels()];
98  for (int i = 0; i < this->getBarrels(); i++)
99  {
100    this->objComp[i] = new PNode* [this->getSegs()];
101    this->shootAnim[i] = new Animation3D* [this->getSegs()];
102    for(int j = 0; j < this->getSegs(); j++)
103    {
104      this->objComp[i][j] = new PNode;
105      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
106      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
107    }
108  }
109
110  for (int i = 0; i < this->getBarrels(); i++){
111    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
112    this->shootAnim[i][0]->addKeyFrame(Vector(-0.333, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
113    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
114
115    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
116    this->shootAnim[i][1]->addKeyFrame(Vector(.166, 0.0, 0.0), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
117    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
118  }
119
120  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
121  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
122
123  animation2->setInfinity(ANIM_INF_CONSTANT);
124  animation3->setInfinity(ANIM_INF_CONSTANT);
125
126
127  this->setEmissionPoint(1.3, 0, 0);
128
129  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
130  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
131
132  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
133  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
134}
135
136
137void MediumBlaster::fire()
138{
139  Projectile* pj =  this->getProjectile();
140  if (pj == NULL)
141    return;
142
143  // set the owner
144  pj->setOwner(this->getOwner());
145
146  pj->setParent(PNode::getNullParent());
147
148  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
149
150  pj->setAbsCoor(this->getEmissionPoint());
151  pj->setAbsDir(this->getAbsDir());
152  pj->activate();
153
154  for (int i = 0; i < this->getSegs(); i++)
155    this->shootAnim[this->activeBarrel][i]->replay();
156}
157
158
159/**
160 *  this activates the weapon
161*/
162void MediumBlaster::activate()
163{
164}
165
166/**
167 *  this deactivates the weapon
168*/
169void MediumBlaster::deactivate()
170{
171}
172
173void MediumBlaster::draw() const
174{
175  glMatrixMode(GL_MODELVIEW);
176  glPushMatrix();
177    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
178    Vector tmpRot = this->getAbsDir().getSpacialAxis();
179    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
180    static_cast<StaticModel*>(this->getModel())->draw(0);
181
182  glPushMatrix();
183    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
184    static_cast<StaticModel*>(this->getModel())->draw(1);
185  glPopMatrix();
186
187  glPushMatrix();
188    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
189    static_cast<StaticModel*>(this->getModel())->draw(2);
190  glPopMatrix();
191
192  glPopMatrix();
193}
194
195void MediumBlaster::tick(float dt)
196{
197  if (!Weapon::tickW(dt))
198    return;
199  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
200  {
201    this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png");
202    this->setEnergyWidgetInitialized(true);
203  }
204}
Note: See TracBrowser for help on using the repository browser.