Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

weapon, collision, particles

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