Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc @ 4884

Last change on this file since 4884 was 4884, checked in by bensch, 19 years ago

orxonox/trunk: saver implementation of state-variables.
this step makes the execute function very big, and as such is not the best idea, maybe i will split up the checks in the execute-functions so one has a better insight into what is happening in weapon.
For this maybe a wrapper around fire/reload… functions will be written, that calls them within a fireWeapon/reloadWeapon function

File size: 6.5 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
15   co-programmer:
16
17
18   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
20*/
21
22
23#include "test_gun.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "test_bullet.h"
28
29#include "state.h"
30#include "vector.h"
31#include "list.h"
32#include "animation3d.h"
33#include "sound_engine.h"
34
35#include "object_manager.h"
36
37using namespace std;
38
39
40/**
41 *  standard constructor
42
43   creates a new weapon
44*/
45TestGun::TestGun (PNode* parent, const Vector& coordinate,
46                  const Quaternion& direction, int leftRight)
47  :  Weapon (parent, coordinate, direction)
48{
49  this->setClassID(CL_TEST_GUN, "TestGun");
50
51  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
52  this->leftRight = leftRight;
53
54  this->objectComponent1 = new PNode();
55  this->animation1 = new Animation3D(this->objectComponent1);
56  this->animation2 = new Animation3D(this);
57  this->animation3 = new Animation3D(this);
58  //parent->addChild(this->objectComponent1, PNODE_ALL);
59  this->addChild(this->objectComponent1, PNODE_ALL);
60
61  this->animation1->setInfinity(ANIM_INF_CONSTANT);
62  this->animation2->setInfinity(ANIM_INF_CONSTANT);
63  this->animation3->setInfinity(ANIM_INF_CONSTANT);
64  if( this->leftRight == W_LEFT)
65    {
66      this->projectileOffset = Vector(1.0, 0.0, -0.35);
67
68      this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
69      this->animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
70      this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
71
72      this->animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
73      this->animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
74
75      this->animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
76      this->animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
77    }
78  else if( this->leftRight == W_RIGHT)
79    {
80      this->projectileOffset = Vector(1.0, 0.0, 0.5);
81
82      this->objectComponent1->setRelCoor(Vector(0,0,0.35));
83      this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
84      this->animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
85      this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
86
87      this->animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
88      this->animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
89
90      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
91      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
92    }
93/*
94  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
95  this->weaponSource = new SoundSource(this->fireSound, this);
96  this->weaponSource->setRolloffFactor(.1);*/
97  Projectile* p = new TestBullet(this);
98
99  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
100  //ObjectManager::getInstance()->debug();
101
102  this->setStateDuration(WS_SHOOTING, .2);
103
104  this->energy = 100;
105  this->minCharge = 2;
106
107  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
108}
109
110
111/**
112 *  standard deconstructor
113*/
114TestGun::~TestGun ()
115{
116  // model will be deleted from WorldEntity-destructor
117}
118
119
120/**
121 *  this activates the weapon
122
123   This is needed, since there can be more than one weapon on a ship. the
124   activation can be connected with an animation. for example the weapon is
125   been armed out.
126*/
127void TestGun::activate()
128{
129  this->animation2->replay();
130}
131
132
133/**
134 *  this deactivates the weapon
135
136   This is needed, since there can be more than one weapon on a ship. the
137   activation can be connected with an animation. for example the weapon is
138   been armed out.
139*/
140void TestGun::deactivate()
141{
142  this->animation3->replay();
143}
144
145
146/**
147 *  fires the weapon
148
149   this is called from the player.cc, when fire-button is been pushed
150   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
151*/
152void TestGun::fire()
153{
154  this->energyLoaded -= this->minCharge;
155  Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
156//  weaponSource->play();
157
158  pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset);
159  pj->setAbsDir(this->getAbsDir());
160  pj->setVelocity(this->getVelocity());
161  State::getWorldEntityList()->add(pj);
162
163  this->animation1->replay();
164}
165
166
167/**
168 *  is called, when the weapon gets hit (=collide with something)
169 * @param from which entity it is been hit
170 * @param where it is been hit
171
172   this may not be used, since it would make the game relay complicated when one
173   can destroy the weapons of enemies or vice versa.
174*/
175void TestGun::hit (WorldEntity* entity, Vector* position)
176{}
177
178
179/**
180 *  is called, when the weapon is destroyed
181
182   this is in conjunction with the hit function, so when a weapon is able to get
183   hit, it can also be destoryed.
184*/
185void TestGun::destroy ()
186{}
187
188
189/**
190 *  is called, when there is no fire button pressed
191*/
192void TestGun::weaponIdle()
193{}
194
195
196/**
197 *  this will draw the weapon
198*/
199void TestGun::draw ()
200{
201  /* draw gun body */
202  glMatrixMode(GL_MODELVIEW);
203  glPushMatrix();
204  float matrix[4][4];
205  glTranslatef (this->getAbsCoor ().x,
206                this->getAbsCoor ().y,
207                this->getAbsCoor ().z);
208  this->getAbsDir ().matrix (matrix);
209  glMultMatrixf((float*)matrix);
210  if( this->leftRight == W_RIGHT)
211    glScalef(1.0, 1.0, -1.0);
212  this->model->draw(1);
213  glPopMatrix();
214
215  /* draw objectComponent1: gun coil - animated stuff */
216  glMatrixMode(GL_MODELVIEW);
217  glPushMatrix();
218  glTranslatef (this->objectComponent1->getAbsCoor ().x,
219                this->objectComponent1->getAbsCoor ().y,
220                this->objectComponent1->getAbsCoor ().z);
221  this->objectComponent1->getAbsDir ().matrix (matrix);
222  glMultMatrixf((float*)matrix);
223  this->model->draw(0);
224  glPopMatrix();
225}
226
Note: See TracBrowser for help on using the repository browser.