Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9701 was 9235, checked in by bensch, 18 years ago

merged the presentation back

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
29CREATE_FACTORY(BoomerangGun, CL_BOOMERANG_GUN);
30
31
32/**
33 *  standard constructor
34 *
35 * creates a new BoomerangGun
36 */
37BoomerangGun::BoomerangGun ()
38  : Weapon()
39{
40  this->init();
41}
42
43/**
44 * creates a new BoomerangGun from a TiXmlElement
45 */
46BoomerangGun::BoomerangGun(const TiXmlElement* root)
47{
48  this->init();
49  if (root != NULL)
50    this->loadParams(root);
51}
52
53/**
54 *  standard deconstructor
55*/
56BoomerangGun::~BoomerangGun ()
57{
58  // model will be deleted from WorldEntity-destructor
59}
60
61void BoomerangGun::init()
62{
63  this->setClassID(CL_BOOMERANG_GUN, "BoomerangGun");
64
65
66  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
67  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
68
69  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
70  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
71  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73
74  animation1->setInfinity(ANIM_INF_CONSTANT);
75  animation2->setInfinity(ANIM_INF_CONSTANT);
76
77  this->setStateDuration(WS_SHOOTING, .6);
78  this->setStateDuration(WS_RELOADING, 1.0f);
79  this->setStateDuration(WS_ACTIVATING, .4);
80  this->setStateDuration(WS_DEACTIVATING, .4);
81
82  this->setEnergyMax(100);
83  this->increaseEnergy(100);
84  //this->minCharge = 2;
85
86  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
87  this->setProjectileType(CL_BOOMERANG_PROJECTILE);
88
89  this->loadModel("models/guns/turret1.obj", 5.0);
90
91  this->setEmissionPoint(1.684, 0.472, 0);
92  //this->getProjectileFactory()->prepare(100);
93
94  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
95  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
96  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
97
98}
99
100void BoomerangGun::loadParams(const TiXmlElement* root)
101{
102  Weapon::loadParams(root);
103}
104
105void BoomerangGun::activate()
106{
107}
108
109void BoomerangGun::deactivate()
110{
111}
112
113void BoomerangGun::tick(float dt)
114{
115  if (!Weapon::tickW(dt))
116    return;
117
118  Quaternion quat;
119  Vector direction;
120  if (this->getDefaultTarget() == NULL)
121    direction = this->getAbsCoor();
122  else
123    direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor();
124
125  direction.normalize();
126
127  if (likely (this->getParent() != NULL))
128    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
129  else
130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131
132  this->setAbsDirSoft(quat, 5);
133}
134
135void BoomerangGun::fire()
136{
137  Projectile* pj = this->getProjectile();
138  if (pj == NULL)
139    return;
140
141  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */
142            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
143
144
145  pj->setParent(PNode::getNullParent());
146  pj->setAbsCoor(this->getEmissionPoint());
147  pj->setAbsDir(this->getAbsDir());
148  pj->activate();
149}
Note: See TracBrowser for help on using the repository browser.