Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/light_blaster.cc @ 10770

Last change on this file since 10770 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 5.2 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 "light_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
31CREATE_FACTORY(LightBlaster);
32/**
33 * Standard constructor
34 */
35LightBlaster::LightBlaster ()
36 : Weapon()
37{
38    this->init();
39}
40
41LightBlaster::LightBlaster (const TiXmlElement* root = NULL)
42 : Weapon()
43{
44    this->init();
45    if (root != NULL)
46      this->loadParams(root);
47}
48
49/**
50 * Default destructor
51 */
52LightBlaster::~LightBlaster()
53{
54
55  for (int i = 0; i < this->getBarrels(); i++)
56  {
57   //delete [] this->shootAnim[i];
58   delete [] this->objComp[i];
59  }
60  delete [] this->emissionPoint;
61   //delete [] this->shootAnim;
62   delete [] this->objComp;
63
64}
65
66void LightBlaster::loadParams(const TiXmlElement* root)
67{
68  Weapon::loadParams(root);
69}
70
71void LightBlaster::init()
72{
73
74  this->loadModel("models/guns/gatling.obj", 0.333);
75
76
77  this->setStateDuration(WS_SHOOTING, 0.05);  // 20 Schuss pro Sekunde
78  this->setStateDuration(WS_RELOADING, 0);
79  this->setStateDuration(WS_ACTIVATING, .5);
80  this->setStateDuration(WS_DEACTIVATING, 1);
81
82  this->setEnergyMax(500);
83  this->increaseEnergy(500);
84  //this->minCharge = 2;
85
86  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
87//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
88  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
91  this->setProjectileTypeC("LBolt");
92  this->prepareProjectiles(25);
93
94  this->setBarrels(3);
95  this->setSegs(1);
96  this->activeBarrel = 0;
97
98  this->objComp = new PNode**[this->getBarrels()];
99  this->emissionPoint = new PNode*[this->getBarrels()];
100//   this->shootAnim = new Animation3D**[this->getBarrels()];
101  for (int i = 0; i < this->getBarrels(); i++)
102  {
103    this->objComp[i] = new PNode* [this->getSegs()];
104    this->emissionPoint[i] = new PNode;
105    this->emissionPoint[i]->setParent(this);
106    this->emissionPoint[i]->setName("EmissionPoint");
107    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
108    for(int j = 0; j < this->getSegs(); j++)
109    {
110      this->objComp[i][j] = new PNode;
111//       this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
112//       this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
113    }
114  }
115
116  this->emissionPoint[0]->setRelCoor(Vector(2.2, 0.0, 0.1));
117  this->emissionPoint[1]->setRelCoor(Vector(2.2, -0.07, -0.05));
118  this->emissionPoint[2]->setRelCoor(Vector(2.2, 0.07, -0.05));
119
120//   Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this);
121  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
122  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
123
124//   animation1->setInfinity(ANIM_INF_CONSTANT);
125  animation2->setInfinity(ANIM_INF_CONSTANT);
126  animation3->setInfinity(ANIM_INF_CONSTANT);
127
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
136void LightBlaster::fire()
137{
138  Projectile* pj =  this->getProjectile();
139  if (pj == NULL)
140    return;
141
142  // set the owner
143  pj->setOwner(this->getOwner());
144
145  pj->setParent(PNode::getNullParent());
146
147//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
148  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180);
149
150  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
151  pj->setAbsDir(this->getAbsDir());
152//   pj->toList(OM_GROUP_01_PROJ);
153  pj->activate();
154
155//   for (int i = 0; i < this->getSegs(); i++)
156//     this->shootAnim[this->activeBarrel][i]->replay();
157
158  // switch barrel
159  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
160}
161
162/**
163 *  this activates the weapon
164*/
165void LightBlaster::activate()
166{
167}
168
169/**
170 *  this deactivates the weapon
171*/
172void LightBlaster::deactivate()
173{
174}
175
176void LightBlaster::draw() const
177{
178  glMatrixMode(GL_MODELVIEW);
179  glPushMatrix();
180    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
181    Vector tmpRot = this->getAbsDir().getSpacialAxis();
182    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
183    static_cast<StaticModel*>(this->getModel())->draw();
184  glPopMatrix();
185
186}
187
188void LightBlaster::tick(float dt)
189{
190  if (!Weapon::tickW(dt))
191    return;
192  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
193  {
194    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
195    this->setEnergyWidgetInitialized(true);
196  }
197}
Note: See TracBrowser for help on using the repository browser.