Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/spike_thrower.cc @ 10683

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

merged cleanup into trunk (only improvements)

File size: 4.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//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "spike_thrower.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/projectile.h"
21#include "world_entities/projectiles/spike_ball.h"
22#include "world_entities/projectiles/spike.h"
23
24#include "model.h"
25
26#include "state.h"
27#include "animation3d.h"
28
29#include <list>
30#include "util/state.h"
31
32#include "util/loading/factory.h"
33
34#include "elements/glgui_energywidgetvertical.h"
35
36
37
38using namespace std;
39
40ObjectListDefinition(SpikeThrower);
41CREATE_FACTORY(SpikeThrower);
42
43/**
44 *  standard constructor
45 *
46 * creates a new SpikeThrower
47 */
48SpikeThrower::SpikeThrower()
49  : Weapon()
50{
51  this->init();
52}
53
54/**
55 * creates a new SpikeThrower from a TiXmlElement
56 */
57SpikeThrower::SpikeThrower(const TiXmlElement* root)
58{
59  this->init();
60  if (root != NULL)
61    this->loadParams(root);
62}
63
64/**
65 *  standard deconstructor
66*/
67SpikeThrower::~SpikeThrower ()
68{
69
70  // model will be deleted from WorldEntity-destructor
71}
72
73void SpikeThrower::init()
74{
75  this->registerObject(this, SpikeThrower::_objectList);
76/*
77  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
78  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
79
80  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
83  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
84
85  animation1->setInfinity(ANIM_INF_CONSTANT);
86  animation2->setInfinity(ANIM_INF_CONSTANT);*/
87
88  this->setStateDuration(WS_SHOOTING, .6);
89  this->setStateDuration(WS_RELOADING, 1.0f);
90  this->setStateDuration(WS_ACTIVATING, .4);
91  this->setStateDuration(WS_DEACTIVATING, .4);
92
93  this->setEnergyMax(10);
94  this->increaseEnergy(10);
95  //this->minCharge = 2;
96
97  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
98  this->setProjectileTypeC("SpikeBall");
99
100//   this->loadModel("models/guns/turret1.obj", 1.0);
101
102  this->setEmissionPoint(2, 0, 0);
103  this->getProjectileFactory()->prepare(50);
104
105  this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_1.wav");
106  this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav");
107//   this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav");
108
109}
110
111void SpikeThrower::loadParams(const TiXmlElement* root)
112{
113  Weapon::loadParams(root);
114}
115
116void SpikeThrower::activate()
117{
118}
119
120void SpikeThrower::deactivate()
121{
122}
123
124void SpikeThrower::tick(float dt)
125{
126  if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized)
127  {
128    this->energyWidget->setDisplayedImage("textures/gui/gui_spikeball.png");
129    this->isEnergyWidgetInitialized = true;
130  }
131
132  if (!Weapon::tickW(dt))
133    return;
134
135  Quaternion quat;
136  Vector direction;
137  if (this->getDefaultTarget() == NULL)
138    direction = this->getAbsCoor();
139  else
140    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
141
142  direction.normalize();
143
144  if (likely (this->getParent() != NULL))
145    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
146  else
147    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
148
149  this->setAbsDirSoft(quat, 5);
150}
151
152void SpikeThrower::fire()
153{
154  Projectile* pj =  this->getProjectile();
155  if (pj == NULL)
156    return;
157
158  // set the owner
159  pj->setOwner(this->getOwner());
160
161  pj->setParent(PNode::getNullParent());
162
163  dynamic_cast<SpikeBall*>(pj)->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*110);
164
165  pj->setAbsCoor(this->getEmissionPoint());
166  pj->setAbsDir(this->getAbsDir());
167  pj->activate();
168
169//   this->increaseEnergy( - this->getProjectile()->getMinEnergy());
170
171}
Note: See TracBrowser for help on using the repository browser.