Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/medium_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: 5.1 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}
57
58void MediumBlaster::loadParams(const TiXmlElement* root)
59{
60  Weapon::loadParams(root);
61}
62
63void MediumBlaster::init()
64{
65  this->setScaling(.3333);
66
67  this->loadModel("models/guns/blaster.obj", this->getScaling());
68
69  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
70
71  this->setStateDuration(WS_RELOADING, 0);
72  this->setStateDuration(WS_ACTIVATING, .5);
73  this->setStateDuration(WS_DEACTIVATING, 1);
74
75  this->setEnergyMax(500);
76  this->increaseEnergy(500);
77  //this->minCharge = 2;
78
79  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
80//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
81  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
82
83  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
84  this->setProjectileTypeC("MBolt");
85  this->prepareProjectiles(10);
86
87
88  this->setBarrels(1);
89  this->setSegs(2);
90
91
92  for (int i = 0; i < this->getBarrels(); i++){
93    this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
94    this->getShootAnim(i, 0)->addKeyFrame(Vector(-1.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
95    this->getShootAnim(i, 0)->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
96
97    this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.04, ANIM_LINEAR, ANIM_NULL);
98    this->getShootAnim(i, 1)->addKeyFrame(Vector(.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.15, ANIM_LINEAR, ANIM_NULL);
99    this->getShootAnim(i, 1)->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.01, ANIM_LINEAR, ANIM_NULL);
100  }
101
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  this->setEmissionPoint(Vector(3.9, 0.0, 0.0) * this->getScaling());
109
110  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
111  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
112
113  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
114  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
115}
116
117
118void MediumBlaster::fire()
119{
120  Projectile* pj =  this->getProjectile();
121  if (pj == NULL)
122    return;
123
124  // set the owner
125  pj->setOwner(this->getOwner());
126
127  pj->setParent(PNode::getNullParent());
128
129  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
130
131  pj->setAbsCoor(this->getEmissionPoint());
132  pj->setAbsDir(this->getAbsDir());
133  pj->activate();
134
135  for (int i = 0; i < this->getSegs(); i++)
136    this->getShootAnim(this->getActiveBarrel(), i)->replay(); // FIXME needs clean up
137}
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{
156  glMatrixMode(GL_MODELVIEW);
157  glPushMatrix();
158    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
159    Vector tmpRot = this->getAbsDir().getSpacialAxis();
160    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
161    static_cast<StaticModel*>(this->getModel())->draw(0);
162
163  glPushMatrix();
164    glTranslatef (this->getObjCompx(0,0), this->getObjCompy(0,0), this->getObjCompz(0,0));
165    static_cast<StaticModel*>(this->getModel())->draw(1);
166  glPopMatrix();
167
168  glPushMatrix();
169    glTranslatef (this->getObjCompx(0,1), this->getObjCompy(0,1), this->getObjCompz(0,1));
170    static_cast<StaticModel*>(this->getModel())->draw(2);
171  glPopMatrix();
172
173  glPopMatrix();
174}
175
176void MediumBlaster::tick(float dt)
177{
178  if (!Weapon::tickW(dt))
179    return;
180  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
181  {
182    this->energyWidget->setDisplayedImage("textures/gui/gui_medium_bold.png");
183    this->setEnergyWidgetInitialized(true);
184  }
185}
Note: See TracBrowser for help on using the repository browser.