Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/medium_blaster.cc @ 10772

Last change on this file since 10772 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
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 "medium_blaster.h"
[9975]18#include "world_entities/projectiles/projectile.h"
[9972]19
[9975]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
[10366]31//
[10117]32//ObjectListDefinition(MediumBlaster);
[9975]33CREATE_FACTORY(MediumBlaster);
34/**
35 * Standard constructor
36 */
37MediumBlaster::MediumBlaster ()
38 : Weapon()
39{
40    this->init();
41}
42
[9972]43MediumBlaster::MediumBlaster (const TiXmlElement* root = NULL)
44 : Weapon()
[9975]45{
[9972]46    this->init();
47    if (root != NULL)
48      this->loadParams(root);
[9975]49}
[9972]50
51/**
52 * Default destructor
53 */
54MediumBlaster::~MediumBlaster()
[9975]55{
56}
[9972]57
[9975]58void MediumBlaster::loadParams(const TiXmlElement* root)
59{
60  Weapon::loadParams(root);
61}
[9972]62
[9975]63void MediumBlaster::init()
64{
[10698]65  this->setScaling(.3333);
[9975]66
[10698]67  this->loadModel("models/guns/blaster.obj", this->getScaling());
68
[10036]69  this->setStateDuration(WS_SHOOTING, 0.2);   // 5 Schuss pro Sekunde
[9998]70
[9975]71  this->setStateDuration(WS_RELOADING, 0);
[10771]72  this->setStateDuration(WS_ACTIVATING, .5);
73  this->setStateDuration(WS_DEACTIVATING, 1);
[9975]74
[9998]75  this->setEnergyMax(500);
76  this->increaseEnergy(500);
[9975]77  //this->minCharge = 2;
78
[10415]79  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
[10698]80//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
[10415]81  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
[9975]82
83  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
[10698]84  this->setProjectileTypeC("MBolt");
85  this->prepareProjectiles(10);
[9975]86
[10286]87
88  this->setBarrels(1);
89  this->setSegs(2);
90
91
92  for (int i = 0; i < this->getBarrels(); i++){
[10771]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);
[10286]96
[10771]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);
[10286]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
[10771]108  this->setEmissionPoint(Vector(3.9, 0.0, 0.0) * this->getScaling());
[9975]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
[10098]129  pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160);
[9975]130
131  pj->setAbsCoor(this->getEmissionPoint());
132  pj->setAbsDir(this->getAbsDir());
133  pj->activate();
[10286]134
135  for (int i = 0; i < this->getSegs(); i++)
[10771]136    this->getShootAnim(this->getActiveBarrel(), i)->replay(); // FIXME needs clean up
[9975]137}
138
[10516]139
[9975]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();
[10548]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);
[10286]162
163  glPushMatrix();
[10771]164    glTranslatef (this->getObjCompx(0,0), this->getObjCompy(0,0), this->getObjCompz(0,0));
[10286]165    static_cast<StaticModel*>(this->getModel())->draw(1);
166  glPopMatrix();
167
168  glPushMatrix();
[10771]169    glTranslatef (this->getObjCompx(0,1), this->getObjCompy(0,1), this->getObjCompz(0,1));
[10516]170    static_cast<StaticModel*>(this->getModel())->draw(2);
[10286]171  glPopMatrix();
172
173  glPopMatrix();
[9975]174}
[10516]175
176void MediumBlaster::tick(float dt)
177{
[10539]178  if (!Weapon::tickW(dt))
179    return;
[10516]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.