Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/sound_engine/src/world_entities/test_gun.cc @ 3898

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

orxonox/branches/sound_engine: sound works sloppy, test it

File size: 5.9 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 "stdincl.h"
26#include "world_entity.h"
27#include "model.h"
28#include "test_bullet.h"
29
30#include "vector.h"
31#include "list.h"
32#include "animation3d.h"
33
34#include "resource_manager.h"
35#include "sound_engine.h"
36
37using namespace std;
38
39
40/**
41   \brief standard constructor
42
43   creates a new weapon
44*/
45TestGun::TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight) 
46  :  Weapon (parent, coordinate, direction) 
47{
48  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
49  this->idleTime = 0.2f;
50  this->leftRight = leftRight;
51
52  if( this->leftRight == 0)
53    this->projOffset = new Vector(1.0, 0.0, -0.35);
54  else if( this->leftRight == 1)
55    this->projOffset = new Vector(1.0, 0.0, 0.5);
56
57
58  this->dummy1 = new WorldEntity(); // a world entity that is not drawed: use this for the weapon
59  this->animation = new Animation3D(dummy1);
60
61  parent->addChild(this->dummy1, PNODE_ALL);
62
63  this->animation->setInfinity(ANIM_INF_CONSTANT);
64  // ANIM_LINEAR was ANIM_NEG_EXP
65  if( this->leftRight == 0)
66    {
67      this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR); 
68      this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.5, ANIM_LINEAR);
69      this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR);
70    }
71  else if( this->leftRight == 1)
72    {
73      this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
74      this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.5, ANIM_LINEAR);
75      this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
76    }
77
78  this->shootSound = (Sound*)ResourceManager::getInstance()->load("sound/explo.wav", RESOURCE_SOUND_EFFECT, RP_LEVEL);
79  /*
80  if( this->leftRight == 0)
81    {
82      this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.0, ANIM_NEG_EXP);
83      this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.1, ANIM_NEG_EXP);
84      this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.5, ANIM_NEG_EXP);
85    }
86  else if( this->leftRight == 1)
87    {
88      this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.0, ANIM_NEG_EXP);
89      this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.1, ANIM_NEG_EXP);
90      this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.5, ANIM_NEG_EXP);
91    }
92  */
93}
94
95
96/**
97   \brief standard deconstructor
98*/
99TestGun::~TestGun () 
100{
101  // model will be deleted from WorldEntity-destructor
102}
103
104
105/**
106   \brief this activates the weapon
107
108   This is needed, since there can be more than one weapon on a ship. the
109   activation can be connected with an animation. for example the weapon is
110   been armed out.
111*/
112void TestGun::activate()
113{}
114
115
116/**
117   \brief this deactivates the weapon
118
119   This is needed, since there can be more than one weapon on a ship. the
120   activation can be connected with an animation. for example the weapon is
121   been armed out.
122*/
123void TestGun::deactivate()
124{}
125
126
127/**
128   \brief fires the weapon
129   
130   this is called from the player.cc, when fire-button is been pushed
131*/
132void TestGun::fire()
133{
134  if (likely(this->shootSound != NULL))
135    this->shootSound->play();
136
137  if( !this->hasWeaponIdleTimeElapsed())
138    {
139      this->weaponIdle();
140      return;
141    }
142  Projectile* pj = new TestBullet(this);
143
144  pj->setAbsCoor(this->getAbsCoor() + *this->projOffset);
145  pj->setAbsDir(this->getAbsDir());
146
147  pj->setFlightDirection(this->getAbsDir());
148  pj->setSpeed(this->getSpeed());
149
150  this->worldEntities->add(pj);
151  this->localTime = 0;
152 
153  this->animation->replay();
154
155}
156
157
158/**
159   \brief is called, when the weapon gets hit (=collide with something)
160   \param from which entity it is been hit
161   \param where it is been hit
162
163   this may not be used, since it would make the game relay complicated when one
164   can destroy the weapons of enemies or vice versa.
165*/
166void TestGun::hit (WorldEntity* entity, Vector* position) 
167{}
168
169
170/**
171   \brief is called, when the weapon is destroyed
172
173   this is in conjunction with the hit function, so when a weapon is able to get
174   hit, it can also be destoryed.
175*/
176void TestGun::destroy () 
177{}
178
179
180/**
181   \brief tick signal for time dependent/driven stuff
182*/
183void TestGun::tick (float time) 
184{
185  this->localTime += time;
186}
187
188
189/**
190   \brief is called, when there is no fire button pressed
191*/
192void TestGun::weaponIdle()
193{}
194
195
196/**
197   \brief this will draw the weapon
198*/
199void TestGun::draw () 
200{
201 
202  /* draw gun body 1 */
203  glMatrixMode(GL_MODELVIEW);
204  glPushMatrix();
205  float matrix[4][4];
206 
207  if( this->leftRight == 0)
208    {
209      glTranslatef (this->getAbsCoor ().x, 
210                    this->getAbsCoor ().y, 
211                    this->getAbsCoor ().z);
212
213      this->getAbsDir ().matrix (matrix);
214      glMultMatrixf((float*)matrix);
215      this->model->draw(1);
216    }
217  else if( this->leftRight == 1)
218    {
219      glTranslatef (this->getAbsCoor ().x, 
220                    this->getAbsCoor ().y, 
221                    this->getAbsCoor ().z);
222     
223      this->getAbsDir ().matrix (matrix);
224      glMultMatrixf((float*)matrix);
225      glScalef(1.0, 1.0, -1.0);
226      this->model->draw(1);
227    }
228
229  glPopMatrix();
230
231
232  /* draw gun coil 1 */
233  glMatrixMode(GL_MODELVIEW);
234  glPushMatrix();
235 
236  glTranslatef (this->dummy1->getAbsCoor ().x, 
237                this->dummy1->getAbsCoor ().y, 
238                this->dummy1->getAbsCoor ().z);
239 
240  this->dummy1->getAbsDir ().matrix (matrix);
241  glMultMatrixf((float*)matrix);
242  this->model->draw(0);
243  glPopMatrix();
244}
245
Note: See TracBrowser for help on using the repository browser.