Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/lbolt.cc @ 10063

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

halo effects

File size: 4.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Patrick Boenzli
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
28#include <cassert>
29#include "debug.h"
30
31#include "static_model.h"
32
33
34#include "class_id_DEPRECATED.h"
35ObjectListDefinition(LBolt);
36CREATE_FAST_FACTORY_STATIC(LBolt);
37
38/**
39 *  standard constructor
40*/
41LBolt::LBolt () : Projectile()
42{
43  this->registerObject(this, LBolt::_objectList);
44
45  this->loadModel("models/projectiles/lbolt.obj");
46
47  this->setMinEnergy(1);
48  this->setHealthMax(0);
49  this->lifeSpan = 5.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->angle = 0;
58  this->rotationSpeed = 130;
59
60  this->mat = new Material("lBolt");
61  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
62  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
63  this->mat->setDiffuse(1,1,1);
64  this->mat->setIllum(3);
65  this->mat->setDiffuseMap("maps/lbolt2.png");
66  this->mat->setDiffuseMap("maps/lbolt2.png",1);
67  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
68  dynamic_cast<StaticModel*>(this->getModel())->finalize();
69  this->mat->select();
70
71  this->halo = new Billboard();
72  this->halo->setSize(.5, .5);
73  this->halo->setTexture("hbolt_halo.png");
74}
75
76
77/**
78 *  standard deconstructor
79*/
80LBolt::~LBolt ()
81{
82  // delete this->emitter;
83
84  /* this is normaly done by World.cc by deleting the ParticleEngine */
85  if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1)
86  {
87    //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM))
88    //  delete LBolt::explosionParticles;
89    PRINTF(1)("Deleting LBolt Particles\n");
90    LBolt::explosionParticles = NULL;
91  }
92
93}
94
95SpriteParticles* LBolt::explosionParticles = NULL;
96
97void LBolt::activate()
98{
99  if (unlikely(LBolt::explosionParticles == NULL))
100  {
101    LBolt::explosionParticles = new SpriteParticles(1000);
102    LBolt::explosionParticles->setName("BoltExplosionParticles");
103    LBolt::explosionParticles->setLifeSpan(.5, .3);
104    LBolt::explosionParticles->setRadius(0.0, 10.0);
105    LBolt::explosionParticles->setRadius(.5, 6.0);
106    LBolt::explosionParticles->setRadius(1.0, 3.0);
107    LBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
108    LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
109    LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
110  }
111
112  this->setDamage(5);
113  this->setHealth(0);
114}
115
116
117void LBolt::deactivate()
118{
119  assert (LBolt::explosionParticles != NULL);
120  LBolt::explosionParticles->removeEmitter(this->emitter);
121  this->lifeCycle = 0.0;
122
123  this->toList(OM_NULL);
124  this->removeNode();
125  LBolt::fastFactory->kill(this);
126}
127
128
129void LBolt::collidesWith(WorldEntity* entity, const Vector& location)
130{
131  if (this->hitEntity != entity && entity->isA(CL_NPC))
132    this->destroy( entity );
133  this->hitEntity = entity;
134}
135
136/**
137 *  signal tick, time dependent things will be handled here
138 * @param dt time since last tick
139*/
140void LBolt::tick (float dt)
141{
142  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
143  Vector v = this->velocity * dt;
144  this->shiftCoor(v);
145
146  if (this->tickLifeCycle(dt))
147    this->deactivate();
148
149  angle += rotationSpeed * dt;
150}
151
152/**
153 *  the function gets called, when the projectile is destroyed
154*/
155void LBolt::destroy (WorldEntity* killer)
156{
157  Projectile::destroy( killer );
158  PRINTF(5)("DESTROY LBolt\n");
159  this->lifeCycle = .95; //!< @todo calculate this usefully.
160
161  this->emitter->setSystem(LBolt::explosionParticles);
162}
163
164
165void LBolt::draw () const
166{
167  glPushAttrib(GL_ENABLE_BIT);
168  //glDisable(GL_LIGHTING);
169
170  glMatrixMode(GL_MODELVIEW);
171  glPushMatrix();
172
173  float matrix[4][4];
174  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
175
176  glRotatef(angle, 1.0, 0.0, 0.0);
177  this->getAbsDir().matrix (matrix);
178  glMultMatrixf((float*)matrix);
179  this->getModel()->draw();
180
181  this->halo->draw();
182
183//   this->mat->select();
184//   dynamic_cast<StaticModel*>(this->getModel())->draw();
185//   this->mat->select();
186//   dynamic_cast<StaticModel*>(this->getModel())->draw();
187//   this->mat->unselect();
188//   this->mat->unselect();
189  glPopMatrix();
190
191  glPopAttrib();
192}
193
Note: See TracBrowser for help on using the repository browser.