Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/swarm_projectile.cc @ 10005

Last change on this file since 10005 was 10004, checked in by marcscha, 18 years ago

see changelog

File size: 6.2 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 "swarm_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#include "class_id_DEPRECATED.h"
29
30ObjectListDefinitionID(SwarmProjectile, CL_SWARM_PROJECTILE);
31CREATE_FAST_FACTORY_STATIC(SwarmProjectile);
32
33/**
34 *  standard constructor
35*/
36SwarmProjectile::SwarmProjectile () : Projectile()
37{
38
39  this->loadModel("models/projectiles/orx-rocket.obj", 0.5);
40  this->loadExplosionSound("sound/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*/
58SwarmProjectile::~SwarmProjectile ()
59{
60  // delete this->emitter;
61
62  /* this is normaly done by World.cc by deleting the ParticleEngine */
63  if (SwarmProjectile::trailParticles != NULL && SwarmProjectile::objectList().size() <= 1)
64  {
65    if (ParticleSystem::objectList().exists(SwarmProjectile::trailParticles))
66      delete SwarmProjectile::trailParticles;
67    SwarmProjectile::trailParticles = NULL;
68  }
69  if (SwarmProjectile::explosionParticles != NULL && SwarmProjectile::objectList().size() <= 1)
70  {
71    if (ParticleSystem::objectList().exists(SwarmProjectile::explosionParticles))
72      delete SwarmProjectile::explosionParticles;
73    SwarmProjectile::explosionParticles = NULL;
74  }
75
76}
77
78SpriteParticles* SwarmProjectile::trailParticles = NULL;
79SpriteParticles* SwarmProjectile::explosionParticles = NULL;
80
81
82
83void SwarmProjectile::activate()
84{
85  if (unlikely(SwarmProjectile::trailParticles == NULL))
86  {
87    SwarmProjectile::trailParticles = new SpriteParticles(2000);
88    SwarmProjectile::trailParticles->setName("BoomerangProjectileTrailParticles");
89    SwarmProjectile::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
90    SwarmProjectile::trailParticles->setLifeSpan(1.0, .3);
91    SwarmProjectile::trailParticles->setRadius(0.0, .5);
92    SwarmProjectile::trailParticles->setRadius(0.2, 4.0);
93    SwarmProjectile::trailParticles->setRadius(.5, 1.5);
94    SwarmProjectile::trailParticles->setRadius(1.0, 1.5);
95    SwarmProjectile::trailParticles->setColor(0.0, 1,0,0,.7);
96    SwarmProjectile::trailParticles->setColor(0.2, .8,.8,0,.5);
97    SwarmProjectile::trailParticles->setColor(0.5, .8,.8,.8,.8);
98    SwarmProjectile::trailParticles->setColor(1.0, .8,.8,.8,.0);
99  }
100  if (unlikely(SwarmProjectile::explosionParticles == NULL))
101  {
102    SwarmProjectile::explosionParticles = new SpriteParticles(200);
103    SwarmProjectile::explosionParticles->setName("BoomerangProjectileExplosionParticles");
104    SwarmProjectile::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
105    SwarmProjectile::explosionParticles->setLifeSpan(.5, .3);
106    SwarmProjectile::explosionParticles->setRadius(0.0, 10);
107    SwarmProjectile::explosionParticles->setRadius(.5, 15.0);
108    SwarmProjectile::explosionParticles->setRadius(1.0, 10.0);
109    SwarmProjectile::explosionParticles->setColor(0.0, 0,1,0,1);
110    SwarmProjectile::explosionParticles->setColor(0.5, .8,.8,0,.8);
111    SwarmProjectile::explosionParticles->setColor(0.8, .8,.8,.3,.8);
112    SwarmProjectile::explosionParticles->setColor(1.0, 1,1,1,.0);
113  }
114
115  this->emitter->setSystem(SwarmProjectile::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 SwarmProjectile::deactivate()
126{
127  this->emitter->setSystem(NULL);
128  this->lifeCycle = 0.0;
129
130  this->toList(OM_DEAD);
131  this->removeNode();
132  SwarmProjectile::fastFactory->kill(this);
133}
134
135
136void SwarmProjectile::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 SwarmProjectile::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 SwarmProjectile::destroy (WorldEntity* killer)
185{
186
187  printf("THIS SHOULD WORLk\n");
188
189  Projectile::destroy( killer );
190  PRINTF(5)("DESTROY SwarmProjectile\n");
191  this->lifeCycle = .95; //!< @todo calculate this usefully.
192  this->emitter->setSystem(SwarmProjectile::explosionParticles);
193
194  this->emitter->setEmissionRate(1000.0);
195  this->emitter->setEmissionVelocity(50.0);
196  //  this->deactivate();
197
198}
199
200
201void SwarmProjectile::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.