Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10627 was 10317, checked in by patrick, 18 years ago

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

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