Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10562 was 10516, checked in by patrick, 18 years ago

merged playability back to trunk

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