Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

addition of local travel speed, removal of path hacks

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