Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/spike.cc @ 10743

Last change on this file since 10743 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 4.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004-2006 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: Nicolas Schlumberger, Marc Schaerrer
13   co-programmer: Benjamin Grauer
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "spike.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "particles/dot_emitter.h"
26#include "particles/sprite_particles.h"
27
28#include <cassert>
29#include "debug.h"
30
31#include "space_ships/space_ship.h"
32
33
34
35ObjectListDefinition(Spike);
36CREATE_FAST_FACTORY_STATIC(Spike);
37
38/**
39 *  standard constructor
40*/
41Spike::Spike () : Projectile()
42{
43  this->registerObject(this, Spike::_objectList);
44
45  this->loadModel("models/projectiles/spike.obj", 2);
46
47  this->setMinEnergy(1);
48  this->setHealthMax(0);
49  this->lifeSpan = 2.0;
50
51  this->emitter = new DotEmitter(100, 5, M_2_PI);
52  this->emitter->setParent(this);
53  this->emitter->setSpread(M_PI, M_PI);
54  this->emitter->setEmissionRate(300.0);
55  this->emitter->setEmissionVelocity(50.0);
56
57  this->angle = 0;
58  this->rotationSpeed = 130;
59}
60
61
62/**
63 *  standard deconstructor
64*/
65Spike::~Spike ()
66{
67  // delete this->emitter;
68
69  /* this is normaly done by World.cc by deleting the ParticleEngine */
70  if (Spike::explosionParticles != NULL && Spike::objectList().size() <= 1)
71  {
72    //if (ClassList::exists(Spike::explosionParticles, CL_PARTICLE_SYSTEM))
73    //  delete Spike::explosionParticles;
74    PRINTF(1)("Deleting Spike Particles\n");
75/*
76  if (Spike::objectList().exists(Spike::explosionParticles))
77      delete Spike::explosionParticles; */
78    Spike::explosionParticles = NULL;
79  }
80
81}
82
83SpriteParticles* Spike::explosionParticles = NULL;
84
85void Spike::activate()
86{
87  if (unlikely(Spike::explosionParticles == NULL))
88  {
89    Spike::explosionParticles = new SpriteParticles(1000);
90    Spike::explosionParticles->setName("SpikeExplosionParticles");
91    Spike::explosionParticles->setLifeSpan(.5, .3);
92    Spike::explosionParticles->setRadius(0.0, 10.0);
93    Spike::explosionParticles->setRadius(.5, 6.0);
94    Spike::explosionParticles->setRadius(1.0, 3.0);
95    Spike::explosionParticles->setColor(0.0, 1,1,0,.9);
96    Spike::explosionParticles->setColor(0.5, .8,.8,0,.5);
97    Spike::explosionParticles->setColor(1.0, .8,.8,.7,.0);
98  }
99
100  this->setDamage(5);
101  this->setHealth(0);
102}
103
104
105void Spike::deactivate()
106{
107  assert (Spike::explosionParticles != NULL);
108  //Spike::explosionParticles->removeEmitter(this->emitter);
109  this->emitter->setSystem(NULL);
110  this->lifeCycle = 0.0;
111
112  this->toList(OM_NULL);
113//   this->removeNode();
114  Spike::fastFactory->kill(this);
115}
116
117/*
118void Spike::collidesWith(WorldEntity* entity, const Vector& location)
119{
120  PRINTF(0)("Collision with Spike\n");
121  if (this->hitEntity != entity && entity->isA(CL_NPC))
122    this->destroy( entity );
123  this->hitEntity = entity;
124  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
125//   this->deactivate();
126}*/
127
128/**
129 *  signal tick, time dependent things will be handled here
130 * @param dt time since last tick
131*/
132void Spike::tick (float dt)
133{
134  Vector v = this->velocity * dt;
135  this->shiftCoor(v);
136
137  if (this->tickLifeCycle(dt))
138    this->deactivate();
139
140  angle += rotationSpeed * dt;
141}
142
143/**
144 *  the function gets called, when the projectile is destroyed
145*/
146void Spike::destroy (WorldEntity* killer)
147{
148  Projectile::destroy( killer );
149  PRINTF(5)("DESTROY Spike\n");
150  this->lifeCycle = .95; //!< @todo calculate this usefully.
151
152  this->emitter->setSystem(Spike::explosionParticles);
153}
154
155
156void Spike::draw () const
157{
158  glPushAttrib(GL_ENABLE_BIT);
159  glMatrixMode(GL_MODELVIEW);
160  glPushMatrix();
161
162  float matrix[4][4];
163  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
164  Vector tmpRot = this->getAbsDir().getSpacialAxis();
165  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
166  glRotatef(angle, 1.0, 0.0, 0.0);
167
168  this->getAbsDir().matrix (matrix);
169  glMultMatrixf((float*)matrix);
170  this->getModel()->draw();
171
172  glPopMatrix();
173  glPopAttrib();
174}
175
Note: See TracBrowser for help on using the repository browser.