Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/mbolt.cc @ 10371

Last change on this file since 10371 was 10368, checked in by patrick, 18 years ago

merged the branche playability into the trunk

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