Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/rocket.cc @ 5495

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

orxonox/trunk: revision should be visible

File size: 5.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 "list.h"
24#include "class_list.h"
25
26#include "particle_engine.h"
27#include "particle_emitter.h"
28#include "particle_system.h"
29#include "text.h"
30
31
32using namespace std;
33
34CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET);
35
36unsigned int Points = 0;
37Text* pointsText = NULL;
38
39
40/**
41 *  standard constructor
42*/
43Rocket::Rocket () : Projectile()
44{
45  this->setClassID(CL_TEST_BULLET, "Rocket");
46
47  float modelSize = .3;
48  this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3);
49
50  this->energyMin = 1;
51  this->energyMax = 10;
52  this->remove();
53  this->lifeSpan = 2;
54
55  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
56  this->emitter->setParent(this);
57  this->emitter->setSpread(M_PI, M_PI);
58}
59
60
61/**
62 *  standard deconstructor
63*/
64Rocket::~Rocket ()
65{
66  // delete this->emitter;
67
68  /* this is normaly done by World.cc by deleting the ParticleEngine */
69  if (Rocket::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
70  {
71    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM))
72      delete Rocket::trailParticles;
73    Rocket::trailParticles = NULL;
74    Points = 0;
75    delete pointsText;
76    pointsText = NULL;
77  }
78  if (Rocket::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
79  {
80    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM))
81      delete Rocket::explosionParticles;
82    Rocket::explosionParticles = NULL;
83  }
84
85}
86
87ParticleSystem* Rocket::trailParticles = NULL;
88ParticleSystem* Rocket::explosionParticles = NULL;
89
90void Rocket::activate()
91{
92  State::getWorldEntityList()->add(this);
93  if (unlikely(Rocket::trailParticles == NULL))
94  {
95    Rocket::trailParticles = new ParticleSystem(2000, PARTICLE_SPRITE);
96    Rocket::trailParticles->setName("RocketTrailParticles");
97    Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
98    Rocket::trailParticles->setLifeSpan(1.0, .3);
99    Rocket::trailParticles->setRadius(0.0, .5);
100    Rocket::trailParticles->setRadius(0.2, 2.0);
101    Rocket::trailParticles->setRadius(.5, .8);
102    Rocket::trailParticles->setRadius(1.0, .8);
103    Rocket::trailParticles->setColor(0.0, 1,0,0,.7);
104    Rocket::trailParticles->setColor(0.2, .8,.8,0,.5);
105    Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8);
106    Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0);
107
108    pointsText = new Text();
109    pointsText->setAbsCoor2D(5, 100);
110    pointsText->setText("0");
111    pointsText->setColor(1,0,0);
112    pointsText->setSize(50);
113
114  }
115  if (unlikely(Rocket::explosionParticles == NULL))
116  {
117    Rocket::explosionParticles = new ParticleSystem(200, PARTICLE_SPRITE);
118    Rocket::explosionParticles->setName("RocketExplosionParticles");
119    Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
120    Rocket::explosionParticles->setLifeSpan(.6, .3);
121    Rocket::explosionParticles->setRadius(0.0, 10);
122    Rocket::explosionParticles->setRadius(.5, 20.0);
123    Rocket::explosionParticles->setRadius(1.0, 20.0);
124    Rocket::explosionParticles->setColor(0.0, 0,1,0,1);
125    Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8);
126    Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8);
127    Rocket::explosionParticles->setColor(1.0, 1,1,1,.0);
128  }
129
130  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::trailParticles);
131
132  this->update(0);
133  this->emitter->setEmissionRate(45.0);
134  this->emitter->setEmissionVelocity(0.0);
135}
136
137
138void Rocket::deactivate()
139{
140  ParticleEngine::getInstance()->breakConnections(this->emitter);
141  this->lifeCycle = 0.0;
142
143//  GarbageCollector::getInstance()->collect(this);
144  State::getWorldEntityList()->remove(this);
145  Rocket::fastFactory->kill(this);
146}
147
148
149void Rocket::collidesWith(WorldEntity* entity, const Vector& location)
150{
151  if (this->hitEntity != entity && entity->isA(CL_NPC))
152  {
153    Points += 807187088;
154    char pointTxt[50];
155    sprintf(pointTxt, "points: %d", Points);
156    pointsText->setText(pointTxt);
157    this->destroy();
158  }
159  this->hitEntity = entity;
160}
161
162/**
163 *  signal tick, time dependent things will be handled here
164 * @param time since last tick
165*/
166void Rocket::tick (float time)
167{
168  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
169  Vector v = this->velocity * (time);
170  this->shiftCoor(v);
171
172  this->lifeCycle += time/this->lifeSpan;
173  if( this->lifeCycle >= 1.0)
174    {
175      PRINTF(5)("FINALIZE==========================\n");
176      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
177      PRINTF(5)("FINALIZE===========================\n");
178
179      this->deactivate();
180    }
181}
182
183/**
184 *  the function gets called, when the projectile is destroyed
185*/
186void Rocket::destroy ()
187{
188  PRINTF(5)("DESTROY Rocket\n");
189  this->lifeCycle = .95; //!< @todo calculate this usefully.
190  ParticleEngine::getInstance()->breakConnection(this->emitter, Rocket::trailParticles);
191  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::explosionParticles);
192
193  this->emitter->setEmissionRate(1000.0);
194  this->emitter->setEmissionVelocity(50.0);
195//  this->deactivate();
196
197}
198
199
200void Rocket::draw ()
201{
202  glMatrixMode(GL_MODELVIEW);
203  glPushMatrix();
204
205  float matrix[4][4];
206  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
207  this->getAbsDir().matrix (matrix);
208  glMultMatrixf((float*)matrix);
209  glScalef(2.0, 2.0, 2.0);
210  this->model->draw();
211
212  glPopMatrix();
213}
214
Note: See TracBrowser for help on using the repository browser.