Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/vs-enhencements/src/world_entities/projectiles/lbolt.cc @ 10691

Last change on this file since 10691 was 10649, checked in by nicolasc, 18 years ago

added nadion blast
fine tuned weapon timing / prepared projectiles

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