Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/projectiles/boomerang_projectile.cc @ 10767

Last change on this file since 10767 was 10415, checked in by patrick, 18 years ago

changed the path names to reflect the new data repos

File size: 6.5 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific
13   main-programmer: Silvan Nellen
14   co-programmer:
15
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
18
19#include "boomerang_projectile.h"
20
21#include "state.h"
22
23#include "particles/dot_emitter.h"
24#include "particles/sprite_particles.h"
25
26#include "debug.h"
27
28
29ObjectListDefinition(BoomerangProjectile);
30CREATE_FAST_FACTORY_STATIC(BoomerangProjectile);
31
32/**
33 *  standard constructor
34*/
35BoomerangProjectile::BoomerangProjectile () : Projectile()
36{
37  this->registerObject(this, BoomerangProjectile::_objectList);
38
39  this->loadModel("models/projectiles/orx-rocket.obj", 2.0);
40  this->loadExplosionSound("sounds/explosions/explosion_4.wav");
41
42
43  this->setMinEnergy(1);
44  this->setHealthMax(10);
45  this->lifeSpan = 2.0;
46  this->agility = 3.5;
47  this->maxVelocity = 150;
48
49  this->emitter = new DotEmitter(100, 5, M_2_PI);
50  this->emitter->setParent(this);
51  this->emitter->setSpread(M_PI, M_PI);
52}
53
54
55/**
56 *  standard deconstructor
57*/
58BoomerangProjectile::~BoomerangProjectile ()
59{
60  // delete this->emitter;
61
62  /* this is normaly done by World.cc by deleting the ParticleEngine */
63  if (BoomerangProjectile::trailParticles != NULL && BoomerangProjectile::objectList().size() <= 1)
64  {
65    if (ParticleSystem::objectList().exists(BoomerangProjectile::trailParticles))
66      delete BoomerangProjectile::trailParticles;
67    BoomerangProjectile::trailParticles = NULL;
68  }
69  if (BoomerangProjectile::explosionParticles != NULL && BoomerangProjectile::objectList().size() <= 1)
70  {
71    if (ParticleSystem::objectList().exists(BoomerangProjectile::explosionParticles))
72      delete BoomerangProjectile::explosionParticles;
73    BoomerangProjectile::explosionParticles = NULL;
74  }
75
76}
77
78SpriteParticles* BoomerangProjectile::trailParticles = NULL;
79SpriteParticles* BoomerangProjectile::explosionParticles = NULL;
80
81
82
83void BoomerangProjectile::activate()
84{
85  if (unlikely(BoomerangProjectile::trailParticles == NULL))
86  {
87    BoomerangProjectile::trailParticles = new SpriteParticles(2000);
88    BoomerangProjectile::trailParticles->setName("BoomerangProjectileTrailParticles");
89    BoomerangProjectile::trailParticles->setMaterialTexture("textures/radial-trans-noise.png");
90    BoomerangProjectile::trailParticles->setLifeSpan(1.0, .3);
91    BoomerangProjectile::trailParticles->setRadius(0.0, .5);
92    BoomerangProjectile::trailParticles->setRadius(0.2, 4.0);
93    BoomerangProjectile::trailParticles->setRadius(.5, 1.5);
94    BoomerangProjectile::trailParticles->setRadius(1.0, 1.5);
95    BoomerangProjectile::trailParticles->setColor(0.0, 1,0,0,.7);
96    BoomerangProjectile::trailParticles->setColor(0.2, .8,.8,0,.5);
97    BoomerangProjectile::trailParticles->setColor(0.5, .8,.8,.8,.8);
98    BoomerangProjectile::trailParticles->setColor(1.0, .8,.8,.8,.0);
99  }
100  if (unlikely(BoomerangProjectile::explosionParticles == NULL))
101  {
102    BoomerangProjectile::explosionParticles = new SpriteParticles(200);
103    BoomerangProjectile::explosionParticles->setName("BoomerangProjectileExplosionParticles");
104    BoomerangProjectile::explosionParticles->setMaterialTexture("textures/radial-trans-noise.png");
105    BoomerangProjectile::explosionParticles->setLifeSpan(.5, .3);
106    BoomerangProjectile::explosionParticles->setRadius(0.0, 10);
107    BoomerangProjectile::explosionParticles->setRadius(.5, 15.0);
108    BoomerangProjectile::explosionParticles->setRadius(1.0, 10.0);
109    BoomerangProjectile::explosionParticles->setColor(0.0, 0,1,0,1);
110    BoomerangProjectile::explosionParticles->setColor(0.5, .8,.8,0,.8);
111    BoomerangProjectile::explosionParticles->setColor(0.8, .8,.8,.3,.8);
112    BoomerangProjectile::explosionParticles->setColor(1.0, 1,1,1,.0);
113  }
114
115  this->emitter->setSystem(BoomerangProjectile::trailParticles);
116
117  this->updateNode(0);
118  this->emitter->setEmissionRate(45.0);
119  this->emitter->setEmissionVelocity(0.0);
120
121  this->setHealth(10.0* (float)rand()/(float)RAND_MAX);
122}
123
124
125void BoomerangProjectile::deactivate()
126{
127  this->emitter->setSystem(NULL);
128  this->lifeCycle = 0.0;
129
130  this->toList(OM_DEAD);
131  this->removeNode();
132  BoomerangProjectile::fastFactory->kill(this);
133}
134
135
136void BoomerangProjectile::collidesWith(WorldEntity* entity, const Vector& location)
137{
138  if (this->hitEntity != entity)
139    this->destroy( entity );
140  this->hitEntity = entity;
141}
142
143/**
144 *  signal tick, time dependent things will be handled here
145 * @param time since last tick
146*/
147void BoomerangProjectile::tick (float time)
148{
149
150  Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0);
151
152  {
153    speed = velocity.len();
154    diffVector = ((targetFarFarAway - this->getAbsCoor()).getNormalized());
155
156    if(velocity.dot(diffVector) != 0)
157    {
158      correctionVector = (( ( diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility;
159
160      if( (diffVector *  (speed * speed/( velocity.dot(diffVector ) ) ) -velocity).len() < agility )
161        velocity = ((diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )).getNormalized())*agility;
162      else if(velocity.dot(diffVector) > 0)
163        velocity += correctionVector;
164      else if (velocity.dot(diffVector) < 0)
165        velocity -= correctionVector;
166    }
167    else
168      velocity += diffVector * agility;
169
170    this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)));
171  }
172
173  velocity *= maxVelocity/velocity.len();
174  Vector v = this->velocity * (time);
175  this->shiftCoor(v);
176
177  if(this->tickLifeCycle(time))
178    this->deactivate();
179}
180
181/**
182 *  the function gets called, when the projectile is destroyed
183 */
184void BoomerangProjectile::destroy (WorldEntity* killer)
185{
186
187  printf("THIS SHOULD WORLk\n");
188
189  Projectile::destroy( killer );
190  PRINTF(5)("DESTROY BoomerangProjectile\n");
191  this->lifeCycle = .95; //!< @todo calculate this usefully.
192  this->emitter->setSystem(BoomerangProjectile::explosionParticles);
193
194  this->emitter->setEmissionRate(1000.0);
195  this->emitter->setEmissionVelocity(50.0);
196  //  this->deactivate();
197
198}
199
200
201void BoomerangProjectile::draw () const
202{
203  glMatrixMode(GL_MODELVIEW);
204  glPushMatrix();
205
206  float matrix[4][4];
207  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
208  this->getAbsDir().matrix (matrix);
209  glMultMatrixf((float*)matrix);
210  glScalef(2.0, 2.0, 2.0);
211  this->getModel()->draw();
212
213  glPopMatrix();
214
215}
216
Note: See TracBrowser for help on using the repository browser.