Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Last update, collision working again. SEGFAULT problems

File size: 5.3 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
[9999]38#include "class_id_DEPRECATED.h"
[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
[10078]50 
[10042]51  //this->loadModel("models/projectiles/laser.obj");
[9999]52
[10036]53  this->setMinEnergy(4);
[9999]54  this->setHealthMax(0);
[10117]55  this->lifeSpan = 3.0;
[10042]56  this->angle     = 0;
[9999]57
[10064]58
59  //this->emitter = new DotEmitter(1000, 0, 0);
[10113]60  this->emitter = new DotEmitter(50, 0, 0);
[9999]61  this->emitter->setParent(this);
[10064]62  this->emitter->setSpread(M_PI,M_PI);
63  this->emitter->setInheritSpeed(this->velocity.len());
64  this->emitter->setEmissionRate(500.0);
65  this->emitter->setEmissionVelocity(this->velocity.len());
[10042]66
67  this->mat = new Material("mBolt");
68  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
69  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
70  this->mat->setDiffuse(1,1,1);
[10064]71  this->mat->setDiffuseMap("laser_add.png");
[10042]72  this->mat->setDiffuseMap("laser.png",1);
[10064]73
[10042]74  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
75  dynamic_cast<StaticModel*>(this->getModel())->finalize();
[10081]76
[10113]77  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
78  this->buildObbTree(4);
[10081]79 
[10095]80  this->trail = new Trail(6,4,.1, this);
81  //this->trail->setParent( this);
[10081]82  this->trail->setTexture( "maps/laser.png");
[10113]83  this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0));
[9999]84}
85
86
87/**
88 *  standard deconstructor
[10078]89 *
90 */
[9999]91MBolt::~MBolt ()
92{
93  // delete this->emitter;
94
95  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
96  {
[10042]97    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
98      delete MBolt::explosionParticles;
[9999]99    MBolt::explosionParticles = NULL;
[10081]100    PRINTF(1)("Deleting MBolt Explosion Particles\n");
[9999]101  }
[10081]102 
[9999]103}
104
105SpriteParticles* MBolt::explosionParticles = NULL;
106
107void MBolt::activate()
108{
109  if (unlikely(MBolt::explosionParticles == NULL))
110  {
111    MBolt::explosionParticles = new SpriteParticles(1000);
112    MBolt::explosionParticles->setName("MBoltExplosionParticles");
[10113]113    MBolt::explosionParticles->setLifeSpan(.2, .1);
[9999]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
[10081]122  this->setPhysDamage(10);
123  this->setElecDamage(0);
[9999]124  this->setHealth(0);
[10042]125
126
[10064]127  this->emitter->setSpread(0);
[10078]128  this->emitter->setEmissionRate(10.0);
[10113]129  this->emitter->setEmissionVelocity(50);
[9999]130}
131
132
133void MBolt::deactivate()
134{
135  assert (MBolt::explosionParticles != NULL);
136  MBolt::explosionParticles->removeEmitter(this->emitter);
137  this->lifeCycle = 0.0;
138
[10113]139  this->toList(OM_DEAD);
[10117]140  this->removeNode();
[9999]141  MBolt::fastFactory->kill(this);
142}
143
144
145void MBolt::collidesWith(WorldEntity* entity, const Vector& location)
146{
[10113]147
[10117]148  if (this->hitEntity != entity)
149    this->destroy( entity );
150  this->hitEntity = entity;
151  dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
152  this->destroy(this);
153 
154  return;
155
156  if( entity == NULL || dynamic_cast<SpaceShip*>(entity) == NULL)
[10081]157    return;
158
159  dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage());
[10095]160  //entity->destroy(this);
161  //this->deactivate();
[9999]162}
163
164/**
165 *  signal tick, time dependent things will be handled here
166 * @param dt time since last tick
167*/
168void MBolt::tick (float dt)
169{
170  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
171  Vector v = this->velocity * dt;
172  this->shiftCoor(v);
173
174  if (this->tickLifeCycle(dt))
175    this->deactivate();
[10042]176
177  this->angle += MBolt::rotationSpeed * dt;
[10081]178  this->trail->tick(dt);
[9999]179}
180
181/**
182 *  the function gets called, when the projectile is destroyed
183*/
184void MBolt::destroy (WorldEntity* killer)
185{
[10117]186  //this->deactivate();
[9999]187  Projectile::destroy( killer );
188  PRINTF(5)("DESTROY MBolt\n");
189  this->lifeCycle = .95; //!< @todo calculate this usefully.
190
191  this->emitter->setSystem(MBolt::explosionParticles);
192}
193
194
195void MBolt::draw () const
196{
197  glPushAttrib(GL_ENABLE_BIT);
198  glDisable(GL_LIGHTING);
199
[10042]200  glPushMatrix();
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
[10113]207  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
[10042]208
209  this->mat->select();
210  dynamic_cast<StaticModel*>(this->getModel())->draw();
211  this->mat->unselect();
[10113]212  glScalef(4/.75,16/.7,16/.7);
213  glTranslatef(-3,0,0);
[10081]214  this->trail->draw();
[10042]215  glPopMatrix();
[9999]216  glPopAttrib();
[10042]217
[10117]218}
Note: See TracBrowser for help on using the repository browser.