Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

mBolt related

File size: 5.3 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/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"
35CREATE_FAST_FACTORY_STATIC(MBolt);
36
37/**
38 *  standard constructor
39*/
40MBolt::MBolt () : Projectile()
41{
42
43  this->loadModel("models/projectiles/mbolt.obj",0.25);
44  //this->loadModel("models/projectiles/laser.obj");
45
46  this->setMinEnergy(4);
47  this->setHealthMax(0);
48  this->lifeSpan = 5.0;
49  this->angle     = 0;
50
51  this->emitter = new DotEmitter(40, 0, 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->mat = new Material("mBolt");
58  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
59  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
60  this->mat->setDiffuse(1,1,1);
61  this->mat->setDiffuseMap("laser.png");
62  this->mat->setDiffuseMap("laser.png",1);
63  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
64  dynamic_cast<StaticModel*>(this->getModel())->finalize();
65}
66
67
68/**
69 *  standard deconstructor
70
71/**
72*/
73MBolt::~MBolt ()
74{
75  // delete this->emitter;
76
77  if (MBolt::trailParticles != NULL && MBolt::objectList().size() <= 1)
78  {
79    if (ParticleSystem::objectList().exists(MBolt::trailParticles))
80      delete MBolt::trailParticles;
81    MBolt::trailParticles = NULL;
82  }
83  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
84  {
85    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
86      delete MBolt::explosionParticles;
87    MBolt::explosionParticles = NULL;
88  }
89}
90
91SpriteParticles* MBolt::trailParticles = NULL;
92SpriteParticles* MBolt::explosionParticles = NULL;
93
94void MBolt::activate()
95{
96  if (unlikely(MBolt::trailParticles == NULL))
97  {
98    MBolt::trailParticles = new SpriteParticles(3000);
99    MBolt::trailParticles->setName("BoomerangProjectileTrailParticles");
100    MBolt::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
101    MBolt::trailParticles->setLifeSpan(1, 0);
102    MBolt::trailParticles->setRadius(0.0, 1);
103    MBolt::trailParticles->setRadius(1.0, 1);
104    MBolt::trailParticles->setColor(0.0, 1,0,0,.9);
105    MBolt::trailParticles->setColor(0.2, .8,.2,0,.9);
106    MBolt::trailParticles->setColor(0.5, .8,.4,0,.8);
107    MBolt::trailParticles->setColor(1.0, .8,.8,0,.7);
108  }
109  if (unlikely(MBolt::explosionParticles == NULL))
110  {
111    MBolt::explosionParticles = new SpriteParticles(1000);
112    MBolt::explosionParticles->setName("MBoltExplosionParticles");
113    MBolt::explosionParticles->setLifeSpan(.5, .3);
114    MBolt::explosionParticles->setRadius(0.0, 10.0);
115    MBolt::explosionParticles->setRadius(.5, 6.0);
116    MBolt::explosionParticles->setRadius(1.0, 3.0);
117    MBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
118    MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
119    MBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
120  }
121
122  this->setDamage(50);
123  this->setHealth(0);
124
125  this->emitter->setSystem(MBolt::trailParticles);
126
127  this->updateNode(0);
128  this->emitter->setSpread(0);
129  this->emitter->setEmissionRate(20.0);
130  this->emitter->setEmissionVelocity(this->velocity.len());
131}
132
133
134void MBolt::deactivate()
135{
136  assert (MBolt::trailParticles != NULL);
137  MBolt::trailParticles->removeEmitter(this->emitter);
138
139  assert (MBolt::explosionParticles != NULL);
140  MBolt::explosionParticles->removeEmitter(this->emitter);
141  this->lifeCycle = 0.0;
142
143  this->toList(OM_NULL);
144  this->removeNode();
145  MBolt::fastFactory->kill(this);
146}
147
148
149void MBolt::collidesWith(WorldEntity* entity, const Vector& location)
150{
151  if (this->hitEntity != entity && entity->isA(CL_NPC))
152    this->destroy( entity );
153  this->hitEntity = entity;
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}
171
172/**
173 *  the function gets called, when the projectile is destroyed
174*/
175void MBolt::destroy (WorldEntity* killer)
176{
177  Projectile::destroy( killer );
178  PRINTF(5)("DESTROY MBolt\n");
179  this->lifeCycle = .95; //!< @todo calculate this usefully.
180
181  this->emitter->setSystem(MBolt::explosionParticles);
182}
183
184
185void MBolt::draw () const
186{
187  glPushAttrib(GL_ENABLE_BIT);
188  glDisable(GL_LIGHTING);
189
190  glPushMatrix();
191
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(3.0, 0.7, 0.7);  // no double rescale
199
200  this->mat->select();
201  dynamic_cast<StaticModel*>(this->getModel())->draw();
202  this->mat->unselect();
203  glPopMatrix();
204  glPopAttrib();
205
206
207}
208
Note: See TracBrowser for help on using the repository browser.