Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/rocket.cc @ 7176

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

Destroy Sounds

File size: 4.8 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: Patrick Boenzli
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "rocket.h"
19
20#include "fast_factory.h"
21
22#include "state.h"
23#include "class_list.h"
24
25#include "dot_emitter.h"
26#include "sprite_particles.h"
27
28
29using namespace std;
30
31CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET);
32
33/**
34 *  standard constructor
35*/
36Rocket::Rocket () : Projectile()
37{
38  this->setClassID(CL_ROCKET, "Rocket");
39
40  float modelSize = .3;
41  this->loadModel("models/projectiles/orx-rocket.obj", .3);
42
43  this->setMinEnergy(1);
44  this->setHealthMax(10);
45  this->lifeSpan = 5;
46
47  this->emitter = new DotEmitter(100, 5, M_2_PI);
48  this->emitter->setParent(this);
49  this->emitter->setSpread(M_PI, M_PI);
50}
51
52
53/**
54 *  standard deconstructor
55*/
56Rocket::~Rocket ()
57{
58  // delete this->emitter;
59
60  /* this is normaly done by World.cc by deleting the ParticleEngine */
61  if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1)
62  {
63/*    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM))
64      delete Rocket::trailParticles;*/
65    Rocket::trailParticles = NULL;
66  }
67  if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1)
68  {
69/*    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM))
70      delete Rocket::explosionParticles;*/
71    Rocket::explosionParticles = NULL;
72  }
73
74}
75
76SpriteParticles* Rocket::trailParticles = NULL;
77SpriteParticles* Rocket::explosionParticles = NULL;
78
79void Rocket::activate()
80{
81  if (unlikely(Rocket::trailParticles == NULL))
82  {
83    Rocket::trailParticles = new SpriteParticles(2000);
84    Rocket::trailParticles->setName("RocketTrailParticles");
85    Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
86    Rocket::trailParticles->setLifeSpan(1.0, .3);
87    Rocket::trailParticles->setRadius(0.0, .5);
88    Rocket::trailParticles->setRadius(0.2, 2.0);
89    Rocket::trailParticles->setRadius(.5, .8);
90    Rocket::trailParticles->setRadius(1.0, .8);
91    Rocket::trailParticles->setColor(0.0, 1,0,0,.7);
92    Rocket::trailParticles->setColor(0.2, .8,.8,0,.5);
93    Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8);
94    Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0);
95  }
96  if (unlikely(Rocket::explosionParticles == NULL))
97  {
98    Rocket::explosionParticles = new SpriteParticles(200);
99    Rocket::explosionParticles->setName("RocketExplosionParticles");
100    Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
101    Rocket::explosionParticles->setLifeSpan(.5, .3);
102    Rocket::explosionParticles->setRadius(0.0, 10);
103    Rocket::explosionParticles->setRadius(.5, 15.0);
104    Rocket::explosionParticles->setRadius(1.0, 10.0);
105    Rocket::explosionParticles->setColor(0.0, 0,1,0,1);
106    Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8);
107    Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8);
108    Rocket::explosionParticles->setColor(1.0, 1,1,1,.0);
109  }
110
111  this->emitter->setSystem(Rocket::trailParticles);
112
113  this->updateNode(0);
114  this->emitter->setEmissionRate(45.0);
115  this->emitter->setEmissionVelocity(0.0);
116}
117
118
119void Rocket::deactivate()
120{
121  this->emitter->setSystem(NULL);
122  this->lifeCycle = 0.0;
123  this->toList(OM_NULL);
124
125//  GarbageCollector::getInstance()->collect(this);
126  this->toList(OM_DEAD);
127  Rocket::fastFactory->kill(this);
128}
129
130
131void Rocket::collidesWith(WorldEntity* entity, const Vector& location)
132{
133  if (this->hitEntity != entity)
134    this->destroy();
135  this->hitEntity = entity;
136}
137
138/**
139 *  signal tick, time dependent things will be handled here
140 * @param time since last tick
141*/
142void Rocket::tick (float dt)
143{
144  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
145  Vector v = this->velocity * (dt);
146  this->shiftCoor(v);
147
148  if(this->tickLifeCycle(dt))
149    this->deactivate();
150}
151
152/**
153 *  the function gets called, when the projectile is destroyed
154*/
155void Rocket::destroy ()
156{
157  Projectile::destroy();
158
159  PRINTF(5)("DESTROY Rocket\n");
160  this->lifeCycle = .95; //!< @todo calculate this usefully.
161  this->emitter->setSystem(Rocket::explosionParticles);
162
163  this->emitter->setEmissionRate(1000.0);
164  this->emitter->setEmissionVelocity(50.0);
165//  this->deactivate();
166
167}
168
169
170void Rocket::draw () const
171{
172  glMatrixMode(GL_MODELVIEW);
173  glPushMatrix();
174
175  float matrix[4][4];
176  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
177  this->getAbsDir().matrix (matrix);
178  glMultMatrixf((float*)matrix);
179  glScalef(2.0, 2.0, 2.0);
180  this->getModel()->draw();
181
182  glPopMatrix();
183}
184
Note: See TracBrowser for help on using the repository browser.