Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/hyperblast.cc @ 6810

Last change on this file since 6810 was 6810, checked in by bensch, 18 years ago

trunk: added hyperblaster

File size: 4.6 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: Benjamin Grauer
13   co-programmer: ...
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "hyperblast.h"
19
20#include "fast_factory.h"
21
22#include "state.h"
23#include "class_list.h"
24
25#include "particle_emitter.h"
26#include "sprite_particles.h"
27#include "spark_particles.h"
28
29
30using namespace std;
31
32CREATE_FAST_FACTORY_STATIC(Hyperblast, CL_HYPERBLAST);
33
34/**
35 *  standard constructor
36*/
37Hyperblast::Hyperblast () : Projectile()
38{
39  this->setClassID(CL_HYPERBLAST, "Hyperblast");
40
41  float modelSize = .3;
42  this->loadModel("models/projectiles/orx-hyperblast.obj", .3);
43
44  this->setMinEnergy(1);
45  this->setHealthMax(10);
46  this->lifeSpan = 5;
47
48  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
49  this->emitter->setParent(this);
50  this->emitter->setSpread(M_PI, M_PI);
51}
52
53
54/**
55 *  standard deconstructor
56*/
57Hyperblast::~Hyperblast ()
58{
59  /* this is normaly done by World.cc by deleting the ParticleEngine */
60  if (Hyperblast::extParticles != NULL && ClassList::getList(CL_HYPERBLAST)->size() <= 1)
61  {
62    Hyperblast::extParticles = NULL;
63  }
64  if (Hyperblast::explosionParticles != NULL && ClassList::getList(CL_HYPERBLAST)->size() <= 1)
65  {
66    Hyperblast::explosionParticles = NULL;
67  }
68
69}
70
71SpriteParticles* Hyperblast::extParticles = NULL;
72SparkParticles* Hyperblast::explosionParticles = NULL;
73
74void Hyperblast::activate()
75{
76  if (unlikely(Hyperblast::extParticles == NULL))
77  {
78    Hyperblast::extParticles = new SpriteParticles(2000);
79    Hyperblast::extParticles->setName("HyperblastTrailParticles");
80    Hyperblast::extParticles->setMaterialTexture("maps/radial-trans-noise.png");
81    Hyperblast::extParticles->setLifeSpan(1.0, .3);
82    Hyperblast::extParticles->setRadius(0.0, .5);
83    Hyperblast::extParticles->setRadius(0.2, 2.0);
84    Hyperblast::extParticles->setRadius(.5, .8);
85    Hyperblast::extParticles->setRadius(1.0, .8);
86    Hyperblast::extParticles->setColor(0.0, 1,0,0,.7);
87    Hyperblast::extParticles->setColor(0.2, .8,.8,0,.5);
88    Hyperblast::extParticles->setColor(0.5, .8,.8,.8,.8);
89    Hyperblast::extParticles->setColor(1.0, .8,.8,.8,.0);
90  }
91  if (unlikely(Hyperblast::explosionParticles == NULL))
92  {
93    Hyperblast::explosionParticles = new SparkParticles(200);
94    Hyperblast::explosionParticles->setName("HyperblastExplosionParticles");
95    Hyperblast::explosionParticles->setLifeSpan(.5, .3);
96    Hyperblast::explosionParticles->setRadius(0.0, 10);
97    Hyperblast::explosionParticles->setRadius(.5, 15.0);
98    Hyperblast::explosionParticles->setRadius(1.0, 10.0);
99    Hyperblast::explosionParticles->setColor(0.0, 0,1,0,1);
100    Hyperblast::explosionParticles->setColor(0.5, .8,.8,0,.8);
101    Hyperblast::explosionParticles->setColor(0.8, .8,.8,.3,.8);
102    Hyperblast::explosionParticles->setColor(1.0, 1,1,1,.0);
103  }
104
105  this->emitter->setSystem(Hyperblast::extParticles);
106
107  this->updateNode(0);
108  this->emitter->setEmissionRate(45.0);
109  this->emitter->setEmissionVelocity(0.0);
110}
111
112
113void Hyperblast::deactivate()
114{
115  this->emitter->setSystem(NULL);
116  this->lifeCycle = 0.0;
117  this->toList(OM_NULL);
118
119//  GarbageCollector::getInstance()->collect(this);
120  this->toList(OM_DEAD);
121  Hyperblast::fastFactory->kill(this);
122}
123
124
125void Hyperblast::collidesWith(WorldEntity* entity, const Vector& location)
126{
127  if (this->hitEntity != entity)
128    this->destroy();
129  this->hitEntity = entity;
130}
131
132/**
133 *  signal tick, time dependent things will be handled here
134 * @param time since last tick
135*/
136void Hyperblast::tick (float dt)
137{
138  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
139  Vector v = this->velocity * (dt);
140  this->shiftCoor(v);
141
142  if(this->tickLifeCycle(dt))
143    this->deactivate();
144}
145
146/**
147 *  the function gets called, when the projectile is destroyed
148*/
149void Hyperblast::destroy ()
150{
151  PRINTF(5)("DESTROY Hyperblast\n");
152  this->lifeCycle = .95; //!< @todo calculate this usefully.
153  this->emitter->setSystem(Hyperblast::explosionParticles);
154
155  this->emitter->setEmissionRate(1000.0);
156  this->emitter->setEmissionVelocity(50.0);
157//  this->deactivate();
158
159}
160
161
162void Hyperblast::draw () const
163{
164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
166
167  float matrix[4][4];
168  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
169  this->getAbsDir().matrix (matrix);
170  glMultMatrixf((float*)matrix);
171  glScalef(2.0, 2.0, 2.0);
172  this->getModel()->draw();
173
174  glPopMatrix();
175}
176
Note: See TracBrowser for help on using the repository browser.