Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10636 was 10317, checked in by patrick, 18 years ago

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

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