Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/boomerang_gun.cc @ 10536

Last change on this file since 10536 was 10419, checked in by patrick, 18 years ago

vocals ⇒ voices

File size: 3.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Benjamin Grauer
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "boomerang_gun.h"
18
19#include "weapon_manager.h"
20#include "world_entities/projectiles/projectile.h"
21
22#include "model.h"
23
24#include "state.h"
25#include "animation3d.h"
26
27#include "util/loading/factory.h"
28
29
30ObjectListDefinition(BoomerangGun);
31CREATE_FACTORY(BoomerangGun);
32
33
34/**
35 *  standard constructor
36 *
37 * creates a new BoomerangGun
38 */
39BoomerangGun::BoomerangGun ()
40  : Weapon()
41{
42  this->init();
43}
44
45/**
46 * creates a new BoomerangGun from a TiXmlElement
47 */
48BoomerangGun::BoomerangGun(const TiXmlElement* root)
49{
50  this->init();
51  if (root != NULL)
52    this->loadParams(root);
53}
54
55/**
56 *  standard deconstructor
57*/
58BoomerangGun::~BoomerangGun ()
59{
60  // model will be deleted from WorldEntity-destructor
61}
62
63void BoomerangGun::init()
64{
65  this->registerObject(this, BoomerangGun::_objectList);
66
67
68  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
69  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
70
71  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
75
76  animation1->setInfinity(ANIM_INF_CONSTANT);
77  animation2->setInfinity(ANIM_INF_CONSTANT);
78
79  this->setStateDuration(WS_SHOOTING, .6);
80  this->setStateDuration(WS_RELOADING, 1.0f);
81  this->setStateDuration(WS_ACTIVATING, .4);
82  this->setStateDuration(WS_DEACTIVATING, .4);
83
84  this->setEnergyMax(100);
85  this->increaseEnergy(100);
86  //this->minCharge = 2;
87
88  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
89  this->setProjectileTypeC("BoomerangProjectile");
90
91  this->loadModel("models/guns/turret1.obj", 5.0);
92
93  this->setEmissionPoint(1.684, 0.472, 0);
94  //this->getProjectileFactory()->prepare(100);
95
96  this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_3.wav");
97  this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav");
98  this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav");
99
100}
101
102void BoomerangGun::loadParams(const TiXmlElement* root)
103{
104  Weapon::loadParams(root);
105}
106
107void BoomerangGun::activate()
108{
109}
110
111void BoomerangGun::deactivate()
112{
113}
114
115void BoomerangGun::tick(float dt)
116{
117  if (!Weapon::tickW(dt))
118    return;
119
120  Quaternion quat;
121  Vector direction;
122  if (this->getDefaultTarget() == NULL)
123    direction = this->getAbsCoor();
124  else
125    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
126
127  direction.normalize();
128
129  if (likely (this->getParent() != NULL))
130    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131  else
132    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
133
134  this->setAbsDirSoft(quat, 5);
135}
136
137void BoomerangGun::fire()
138{
139  Projectile* pj = this->getProjectile();
140  if (pj == NULL)
141    return;
142
143  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */
144            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
145
146
147  pj->setParent(PNode::getNullParent());
148  pj->setAbsCoor(this->getEmissionPoint());
149  pj->setAbsDir(this->getAbsDir());
150  pj->activate();
151}
Note: See TracBrowser for help on using the repository browser.