Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/spike_ball.cc @ 10170

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

EOD commit

File size: 4.9 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_ball.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(SpikeBall);
36CREATE_FAST_FACTORY_STATIC(SpikeBall);
37
38/**
39 *  standard constructor
40*/
41SpikeBall::SpikeBall () : Projectile()
42{
43  this->registerObject(this, SpikeBall::_objectList);
44
45  this->loadModel("models/projectiles/spike_ball.obj", .25);
46
47  this->setMinEnergy(1);
48  this->setHealthMax(0);
49  this->lifeSpan = 1.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->speed = 150;
58
59  this->angle = 0;
60  this->rotationSpeed = 130;
61/*
62  this->halo = new Billboard();
63  this->halo->setSize(.35, .35);
64  this->halo->setTexture("hbolt_halo.png");*/
65}
66
67
68/**
69 *  standard deconstructor
70*/
71SpikeBall::~SpikeBall ()
72{
73  // delete this->emitter;
74
75  /* this is normaly done by World.cc by deleting the ParticleEngine */
76  if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1)
77  {
78    //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM))
79    //  delete SpikeBall::explosionParticles;
80    PRINTF(1)("Deleting SpikeBall Particles\n");
81    SpikeBall::explosionParticles = NULL;
82  }
83
84}
85
86SpriteParticles* SpikeBall::explosionParticles = NULL;
87
88void SpikeBall::activate()
89{
90  if (unlikely(SpikeBall::explosionParticles == NULL))
91  {
92    SpikeBall::explosionParticles = new SpriteParticles(1000);
93    SpikeBall::explosionParticles->setName("BoltExplosionParticles");
94    SpikeBall::explosionParticles->setLifeSpan(.5, .3);
95    SpikeBall::explosionParticles->setRadius(0.0, 10.0);
96    SpikeBall::explosionParticles->setRadius(.5, 6.0);
97    SpikeBall::explosionParticles->setRadius(1.0, 3.0);
98    SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9);
99    SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5);
100    SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0);
101  }
102
103  this->setDamage(5);
104  this->setHealth(0);
105}
106
107
108void SpikeBall::deactivate()
109{
110  assert (SpikeBall::explosionParticles != NULL);
111  SpikeBall::explosionParticles->removeEmitter(this->emitter);
112  this->lifeCycle = 0.0;
113
114  this->toList(OM_NULL);
115  this->removeNode();
116  SpikeBall::fastFactory->kill(this);
117}
118
119
120void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location)
121{
122  PRINTF(0)("Collision with SpikeBall\n");
123  if (this->hitEntity != entity && entity->isA(CL_NPC))
124    this->destroy( entity );
125  this->hitEntity = entity;
126  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
127//   this->deactivate();
128}
129/*
130void SpikeBall::blow()
131{
132  const float* v = this->getModel()->getVertexArray();
133  Projectile* pj = NULL;
134
135  for (unsigned int i = 0; i < this->getModel()->getVertexCount(); i++)
136  {
137
138//     v = this->getModel()->getModelInfo
139
140      pj  = this->getProjectile();
141      if (pj == NULL)
142        return;
143
144      if (v[i].x * v[i].x + v[i].y * v[i].y + v[i].z * v[i].z > 4)
145      {
146        pj->setParent(PNode::getNullParent());
147        pj->setAbsCoor(this->getAbsCoor() + v);
148        pj->setAbsDir(v->getNormalized() * this->speed);
149        pj->activate();
150      }
151  }
152}*/
153
154
155/**
156 *  signal tick, time dependent things will be handled here
157 * @param dt time since last tick
158*/
159void SpikeBall::tick (float dt)
160{
161  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
162  Vector v = this->velocity * dt;
163  this->shiftCoor(v);
164
165  if (this->tickLifeCycle(dt)){
166//     this->blow();
167    this->deactivate();
168  }
169
170  angle += rotationSpeed * dt;
171}
172
173/**
174 *  the function gets called, when the projectile is destroyed
175*/
176void SpikeBall::destroy (WorldEntity* killer)
177{
178  Projectile::destroy( killer );
179  PRINTF(5)("DESTROY SpikeBall\n");
180  this->lifeCycle = .95; //!< @todo calculate this usefully.
181
182  this->emitter->setSystem(SpikeBall::explosionParticles);
183}
184
185
186void SpikeBall::draw () const
187{
188  glPushAttrib(GL_ENABLE_BIT);
189  //glDisable(GL_LIGHTING);
190
191  glMatrixMode(GL_MODELVIEW);
192  glPushMatrix();
193
194  float matrix[4][4];
195  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
196
197  glRotatef(angle, 1.0, 0.0, 0.0);
198  this->getAbsDir().matrix (matrix);
199  glMultMatrixf((float*)matrix);
200  this->getModel()->draw();
201
202  this->halo->draw();
203
204  glPopMatrix();
205
206  glPopAttrib();
207}
208
Note: See TracBrowser for help on using the repository browser.