Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/mbolt.cc @ 10274

Last change on this file since 10274 was 10274, checked in by marcscha, 17 years ago

fixes and workaround bugs of Orx

File size: 5.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: Marc Schaerrer
13   co-programmer: Benjamin Grauer
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "mbolt.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 "space_ships/space_ship.h"
29
30#include <cassert>
31#include "debug.h"
32
33#include "static_model.h"
34
35#include "effects/trail.h"
36
37
38#include "class_id_DEPRECATED.h"
39ObjectListDefinition(MBolt);
40CREATE_FAST_FACTORY_STATIC(MBolt);
41
42/**
43 *  standard constructor
44*/
45MBolt::MBolt () : Projectile()
46{
47  this->registerObject(this, MBolt::_objectList);
48  this->loadModel("models/projectiles/mbolt.obj",4);
49
50 
51  //this->loadModel("models/projectiles/laser.obj");
52
53  this->setMinEnergy(4);
54  this->setHealthMax(0);
55  this->lifeSpan = 1.5;
56  this->angle     = 0;
57
58  //this->emitter = new DotEmitter(1000, 0, 0);
59  this->emitter = new DotEmitter(50, 0, 0);
60  this->emitter->setParent(this);
61  this->emitter->setSpread(M_PI,M_PI);
62  this->emitter->setInheritSpeed(this->velocity.len());
63  this->emitter->setEmissionRate(500.0);
64  this->emitter->setEmissionVelocity(this->velocity.len());
65
66  this->mat = new Material("mBolt");
67  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
68  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
69  this->mat->setDiffuse(1,1,1);
70  this->mat->setDiffuseMap("laser_add.png");
71  this->mat->setDiffuseMap("laser.png",1);
72
73  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
74  dynamic_cast<StaticModel*>(this->getModel())->finalize();
75
76  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
77  //this->buildObbTree(4);
78 
79  this->trail = new Trail(6, 4, .1, this);
80  //this->trail->setParent( this);
81  this->trail->setTexture( "maps/laser.png");
82  this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0));
83}
84
85
86/**
87 *  standard deconstructor
88 *
89 */
90MBolt::~MBolt ()
91{
92
93  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
94  {
95    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
96      delete MBolt::explosionParticles;
97    MBolt::explosionParticles = NULL;
98    PRINTF(1)("Deleting MBolt Explosion Particles\n");
99  }
100
101  delete this->emitter;
102  delete this->trail;
103}
104
105SpriteParticles* MBolt::explosionParticles = NULL;
106
107void MBolt::activate()
108{
109  this->toList(OM_ENVIRON);
110  if (unlikely(MBolt::explosionParticles == NULL))
111  {
112    MBolt::explosionParticles = new SpriteParticles(1000);
113    MBolt::explosionParticles->setName("MBoltExplosionParticles");
114    MBolt::explosionParticles->setLifeSpan(.2, .1);
115    MBolt::explosionParticles->setRadius(0.0, 10.0);
116    MBolt::explosionParticles->setRadius(.5, 6.0);
117    MBolt::explosionParticles->setRadius(1.0, 3.0);
118    MBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
119    MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
120    MBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
121  }
122
123  this->setPhysDamage(10);
124  this->setElecDamage(0);
125  this->setHealth(0);
126
127  this->emitter->setSpread(0);
128  this->emitter->setEmissionRate(10.0);
129  this->emitter->setEmissionVelocity(50);
130}
131
132
133void MBolt::deactivate()
134{
135  assert (MBolt::explosionParticles != NULL);
136  MBolt::explosionParticles->removeEmitter(this->emitter);
137  this->lifeCycle = 0.0;
138
139  this->toList(OM_DEAD);
140  this->removeNode();
141  MBolt::fastFactory->kill(this);
142}
143
144void MBolt::hit (float damage, WorldEntity* entity )
145{
146
147  if (this->hitEntity != entity)
148    this->destroy( entity );
149  this->hitEntity = entity;
150 // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
151  //this->destroy(this);
152  this->deactivate();
153 
154  return;
155
156}
157
158/**
159 *  signal tick, time dependent things will be handled here
160 * @param dt time since last tick
161*/
162void MBolt::tick (float dt)
163{
164  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
165  Vector v = this->velocity * dt;
166  this->shiftCoor(v);
167
168  if (this->tickLifeCycle(dt))
169    this->deactivate();
170
171  this->angle += MBolt::rotationSpeed * dt;
172  this->trail->tick(dt);
173
174  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
175  {
176    if( ((*eIterator)->getOMListNumber() == OM_GROUP_00) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
177    {
178      (*eIterator)->hit (this->getDamage(),this);
179      this->deactivate();
180      PRINTF(0)("MBolt destroyed\n");
181    }
182  }
183}
184
185/**
186 *  the function gets called, when the projectile is destroyed
187*/
188void MBolt::destroy (WorldEntity* killer)
189{
190  //this->deactivate();
191  Projectile::destroy( killer );
192  PRINTF(5)("DESTROY MBolt\n");
193  this->lifeCycle = .95; //!< @todo calculate this usefully.
194
195  this->emitter->setSystem(MBolt::explosionParticles);
196}
197
198
199void MBolt::draw () const
200{
201  glPushAttrib(GL_ENABLE_BIT);
202  glDisable(GL_LIGHTING);
203
204  glPushMatrix();
205  float matrix[4][4];
206  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
207  glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile
208  this->getAbsDir().matrix (matrix);
209  glMultMatrixf((float*)matrix);
210
211  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
212
213  this->mat->select();
214  dynamic_cast<StaticModel*>(this->getModel())->draw();
215  this->mat->unselect();
216  glScalef(4/.75,16/.7,16/.7);
217  glTranslatef(-3,0,0);
218  this->trail->draw();
219  glPopMatrix();
220  glPopAttrib();
221
222}
Note: See TracBrowser for help on using the repository browser.