Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/spike.cc @ 10333

Last change on this file since 10333 was 10333, checked in by nicolasc, 17 years ago

bump: black acid splash

File size: 4.0 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#include "class_id_DEPRECATED.h"
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    Spike::explosionParticles = NULL;
76  }
77
78}
79
80SpriteParticles* Spike::explosionParticles = NULL;
81
82void Spike::activate()
83{
84  if (unlikely(Spike::explosionParticles == NULL))
85  {
86    Spike::explosionParticles = new SpriteParticles(1000);
87    Spike::explosionParticles->setName("BoltExplosionParticles");
88    Spike::explosionParticles->setLifeSpan(.5, .3);
89    Spike::explosionParticles->setRadius(0.0, 10.0);
90    Spike::explosionParticles->setRadius(.5, 6.0);
91    Spike::explosionParticles->setRadius(1.0, 3.0);
92    Spike::explosionParticles->setColor(0.0, 1,1,0,.9);
93    Spike::explosionParticles->setColor(0.5, .8,.8,0,.5);
94    Spike::explosionParticles->setColor(1.0, .8,.8,.7,.0);
95  }
96
97  this->setDamage(5);
98  this->setHealth(0);
99}
100
101
102void Spike::deactivate()
103{
104  assert (Spike::explosionParticles != NULL);
105  Spike::explosionParticles->removeEmitter(this->emitter);
106  this->lifeCycle = 0.0;
107
108  this->toList(OM_NULL);
109  this->removeNode();
110  Spike::fastFactory->kill(this);
111}
112
113
114void Spike::collidesWith(WorldEntity* entity, const Vector& location)
115{
116  PRINTF(0)("Collision with Spike\n");
117  if (this->hitEntity != entity && entity->isA(CL_NPC))
118    this->destroy( entity );
119  this->hitEntity = entity;
120  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
121//   this->deactivate();
122}
123
124/**
125 *  signal tick, time dependent things will be handled here
126 * @param dt time since last tick
127*/
128void Spike::tick (float dt)
129{
130  Vector v = this->velocity * dt;
131  this->shiftCoor(v);
132
133  if (this->tickLifeCycle(dt))
134    this->deactivate();
135
136  angle += rotationSpeed * dt;
137}
138
139/**
140 *  the function gets called, when the projectile is destroyed
141*/
142void Spike::destroy (WorldEntity* killer)
143{
144  Projectile::destroy( killer );
145  PRINTF(5)("DESTROY Spike\n");
146  this->lifeCycle = .95; //!< @todo calculate this usefully.
147
148  this->emitter->setSystem(Spike::explosionParticles);
149}
150
151
152void Spike::draw () const
153{
154  glPushAttrib(GL_ENABLE_BIT);
155  glMatrixMode(GL_MODELVIEW);
156  glPushMatrix();
157
158  float matrix[4][4];
159  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
160  Vector tmpRot = this->getAbsDir().getSpacialAxis();
161  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
162  glRotatef(angle, 1.0, 0.0, 0.0);
163
164  this->getAbsDir().matrix (matrix);
165  glMultMatrixf((float*)matrix);
166  this->getModel()->draw();
167
168  glPopMatrix();
169  glPopAttrib();
170}
171
Note: See TracBrowser for help on using the repository browser.