Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

bump

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