Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/lbolt.cc @ 10505

Last change on this file since 10505 was 10505, checked in by snellen, 17 years ago

lbolt,hbolt,spikeball: set visibility false in constructor. the acid splash works so far, all the other projectiles need testing

File size: 4.6 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  this->halo->setVisibiliy(false);
65
66
67}
68
69
70/**
71 *  standard deconstructor
72*/
73LBolt::~LBolt ()
74{
75  // delete this->emitter;
76
77  /* this is normaly done by World.cc by deleting the ParticleEngine */
78  if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1)
79  {
80    //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM))
81    //  delete LBolt::explosionParticles;
82    PRINTF(1)("Deleting LBolt Particles\n");
83    LBolt::explosionParticles = NULL;
84  }
85
86}
87
88SpriteParticles* LBolt::explosionParticles = NULL;
89
90void LBolt::activate()
91{
92  this->halo->setVisibiliy(true);
93  this->origList = this->getOMListNumber();
94  this->toList(OM_ENVIRON);
95  if (unlikely(LBolt::explosionParticles == NULL))
96  {
97    LBolt::explosionParticles = new SpriteParticles(1000);
98    LBolt::explosionParticles->setName("BoltExplosionParticles");
99    LBolt::explosionParticles->setLifeSpan(.5, .3);
100    LBolt::explosionParticles->setRadius(0.0, 10.0);
101    LBolt::explosionParticles->setRadius(.5, 6.0);
102    LBolt::explosionParticles->setRadius(1.0, 3.0);
103    LBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
104    LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
105    LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
106  }
107
108  this->setDamage(5);
109  this->setHealth(0);
110}
111
112
113void LBolt::deactivate()
114{
115  assert (LBolt::explosionParticles != NULL);
116  LBolt::explosionParticles->removeEmitter(this->emitter);
117  this->halo->setVisibiliy(false);
118  this->lifeCycle = 0.0;
119
120  this->toList(OM_DEAD);
121  this->removeNode();
122  LBolt::fastFactory->kill(this);
123}
124
125
126void LBolt::hit (float damage, WorldEntity* entity )
127{
128  PRINTF(0)("Collision with LBolt\n");
129  if (this->hitEntity != entity && entity->isA(NPC::staticClassID()))
130    this->destroy( entity );
131  this->hitEntity = entity;
132  this->deactivate();
133}
134
135/**
136 *  signal tick, time dependent things will be handled here
137 * @param dt time since last tick
138*/
139void LBolt::tick (float dt)
140{
141  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
142  Vector v = this->velocity * dt;
143  this->shiftCoor(v);
144
145  if (this->tickLifeCycle(dt))
146    this->deactivate();
147
148  angle += rotationSpeed * dt;
149
150  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
151  {
152    if( ((*eIterator)->getOMListNumber() != (this->origList -1))   && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
153    {
154      (*eIterator)->hit (this->getDamage(),this);
155      this->deactivate();
156  PRINTF(0)("LBolt destroyed\n");
157    }
158  }
159}
160
161/**
162 *  the function gets called, when the projectile is destroyed
163*/
164void LBolt::destroy (WorldEntity* killer)
165{
166  Projectile::destroy( killer );
167  PRINTF(5)("DESTROY LBolt\n");
168  this->lifeCycle = .95; //!< @todo calculate this usefully.
169
170  this->emitter->setSystem(LBolt::explosionParticles);
171}
172
173
174void LBolt::draw () const
175{
176  glPushAttrib(GL_ENABLE_BIT);
177  //glDisable(GL_LIGHTING);
178
179  glMatrixMode(GL_MODELVIEW);
180  glPushMatrix();
181
182  float matrix[4][4];
183  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
184
185  glRotatef(angle, 1.0, 0.0, 0.0);
186  this->getAbsDir().matrix (matrix);
187  glMultMatrixf((float*)matrix);
188  this->getModel()->draw();
189
190  this->halo->draw();
191
192  glPopMatrix();
193
194  glPopAttrib();
195}
196
Note: See TracBrowser for help on using the repository browser.