Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/explosion.cc @ 7193

Last change on this file since 7193 was 7120, checked in by bensch, 19 years ago

explosion

File size: 3.0 KB
RevLine 
[4593]1/*
[3708]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
[5443]13   co-programmer: Benjamin Grauer
14
[3708]15*/
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3708]17
[7047]18#include "explosion.h"
[3708]19
[4947]20#include "fast_factory.h"
[3708]21
[5443]22#include "state.h"
[5444]23#include "class_list.h"
[5054]24
[7103]25#include "box_emitter.h"
[6621]26#include "sprite_particles.h"
[5443]27
28
[3708]29using namespace std;
30
[7047]31CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION);
[3708]32
[7103]33
[3708]34/**
[4836]35 *  standard constructor
[3708]36*/
[7047]37Explosion::Explosion ()
[3755]38{
[7047]39  this->setClassID(CL_EXPLOSION, "Explosion");
[7104]40  this->toList(OM_DEAD_TICK);
[4597]41
[7106]42  this->emitter = new BoxEmitter(Vector(10,10,10), 500, 45, M_2_PI);
[7047]43  this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
[5443]44  this->emitter->setParent(this);
[5449]45  this->emitter->setSpread(M_PI, M_PI);
[7047]46
47  this->lifeCycle = 0.0f;
[7105]48  this->lifeTime = .5f;
[7047]49
[3755]50}
[3708]51
52
53/**
[4836]54 *  standard deconstructor
[3708]55*/
[7047]56Explosion::~Explosion ()
[3708]57{
[7047]58  delete this->emitter;
[5444]59
[5445]60  /* this is normaly done by World.cc by deleting the ParticleEngine */
[7047]61  if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1)
62     Explosion::explosionParticles = NULL;
[3708]63}
64
[7047]65SpriteParticles* Explosion::explosionParticles = NULL;
[5443]66
[7103]67void Explosion::explode(PNode* position, const Vector& size)
68{
69  Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect());
[7105]70  explosion->setAbsCoor(position->getAbsCoor());
[7103]71  explosion->emitter->setSize(size);
72  explosion->activate();
73}
74
75
[7047]76void Explosion::activate()
[5443]77{
[7047]78  if (unlikely(Explosion::explosionParticles == NULL))
[5447]79  {
[7103]80    Explosion::explosionParticles = new SpriteParticles(5000);
[7047]81    Explosion::explosionParticles->setName("ExplosionExplosionParticles");
82    Explosion::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
[7105]83    Explosion::explosionParticles->setLifeSpan(1.5, .3);
[7047]84    Explosion::explosionParticles->setRadius(0.0, 10);
85    Explosion::explosionParticles->setRadius(.5, 15.0);
86    Explosion::explosionParticles->setRadius(1.0, 10.0);
[7106]87    Explosion::explosionParticles->setColor(0.0, 1,0,0,1);
88    Explosion::explosionParticles->setColor(0.5, .8,.8,0,.5);
89    Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.3);
[7047]90    Explosion::explosionParticles->setColor(1.0, 1,1,1,.0);
[5447]91  }
[5443]92
[7047]93  this->emitter->setSystem(Explosion::explosionParticles);
[7105]94  this->emitter->updateNode(.01);
[7120]95  this->emitter->updateNode(.01);
[7047]96  this->toList(OM_DEAD_TICK);
[7103]97  this->lifeCycle = 0.0;
[5443]98}
99
100
[7047]101void Explosion::deactivate()
[5443]102{
[6619]103  this->emitter->setSystem(NULL);
[7047]104  this->toList(OM_DEAD);
105  Explosion::fastFactory->kill(this);
[5443]106}
107
108
[3708]109/**
[4836]110 *  signal tick, time dependent things will be handled here
111 * @param time since last tick
[3708]112*/
[7047]113void Explosion::tick (float dt)
[3708]114{
[7105]115  printf("%f %f\n", this->lifeCycle, this->lifeTime);
[7047]116  this->lifeCycle += dt;
117  if(this->lifeTime < this->lifeCycle)
[6056]118    this->deactivate();
[3708]119}
Note: See TracBrowser for help on using the repository browser.