Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/projectiles/lbolt.cc @ 10767

Last change on this file since 10767 was 10368, checked in by patrick, 18 years ago

merged the branche playability into the trunk

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