Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10771 was 10771, checked in by nicolasc, 17 years ago

huge diff
cleaned the individual weapons, moved stuff to weapon.{cc,h}
and some minor fixes which popped up then and when

File size: 4.1 KB
RevLine 
[10618]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
[9972]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
[10516]29#include "elements/glgui_energywidgetvertical.h"
30
[9972]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{
[10261]54
[9972]55}
56
57void LightBlaster::loadParams(const TiXmlElement* root)
58{
59  Weapon::loadParams(root);
60}
61
62void LightBlaster::init()
63{
64
[10471]65  this->loadModel("models/guns/gatling.obj", 0.333);
[9972]66
[10415]67
[9998]68  this->setStateDuration(WS_SHOOTING, 0.05);  // 20 Schuss pro Sekunde
[9972]69  this->setStateDuration(WS_RELOADING, 0);
70  this->setStateDuration(WS_ACTIVATING, .5);
71  this->setStateDuration(WS_DEACTIVATING, 1);
72
[9998]73  this->setEnergyMax(500);
74  this->increaseEnergy(500);
[9972]75  //this->minCharge = 2;
76
[10415]77  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
[10516]78//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
[10415]79  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9972]80
81  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10516]82  this->setProjectileTypeC("LBolt");
[10698]83  this->prepareProjectiles(25);
[9972]84
[10152]85  this->setBarrels(3);
[10771]86  this->setSegs(1); //could be left out
[10152]87
[10771]88  this->setEmissionPoint(Vector(2.2, 0.0, 0.1), 0);
89  this->setEmissionPoint(Vector(2.2, -0.07, -0.05), 1);
90  this->setEmissionPoint(Vector(2.2, 0.07, -0.05), 2);
[10152]91
92//   Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this);
[9972]93  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
94  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
95
[10152]96//   animation1->setInfinity(ANIM_INF_CONSTANT);
[9972]97  animation2->setInfinity(ANIM_INF_CONSTANT);
98  animation3->setInfinity(ANIM_INF_CONSTANT);
99
100
101  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
102  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
103
104  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
105  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
106}
107
108void LightBlaster::fire()
109{
110  Projectile* pj =  this->getProjectile();
111  if (pj == NULL)
112    return;
113
[9975]114  // set the owner
115  pj->setOwner(this->getOwner());
116
[9972]117  pj->setParent(PNode::getNullParent());
118
[10044]119//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
[10046]120  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*180);
[9972]121
[10771]122  pj->setAbsCoor(this->getEmissionPoint());
[9972]123  pj->setAbsDir(this->getAbsDir());
[10152]124//   pj->toList(OM_GROUP_01_PROJ);
[9972]125  pj->activate();
[10152]126
[10771]127  this->cycleBarrel();
[9972]128}
129
130/**
131 *  this activates the weapon
132*/
133void LightBlaster::activate()
134{
135}
136
137/**
138 *  this deactivates the weapon
139*/
140void LightBlaster::deactivate()
141{
[9975]142}
143
144void LightBlaster::draw() const
145{
[10152]146  glMatrixMode(GL_MODELVIEW);
147  glPushMatrix();
148    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
149    Vector tmpRot = this->getAbsDir().getSpacialAxis();
150    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
151    static_cast<StaticModel*>(this->getModel())->draw();
152  glPopMatrix();
[10516]153
[9975]154}
[10516]155
156void LightBlaster::tick(float dt)
157{
[10539]158  if (!Weapon::tickW(dt))
159    return;
[10516]160  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
161  {
162    this->energyWidget->setDisplayedImage("textures/gui/gui_light_bolt.png");
163    this->setEnergyWidgetInitialized(true);
164  }
165}
Note: See TracBrowser for help on using the repository browser.