Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/test_bullet.cc @ 5557

Last change on this file since 5557 was 5511, checked in by bensch, 19 years ago

orxonox/trunk: more cleanup of the WorldEntity (includes rearanged)

File size: 5.2 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: Patrick Boenzli
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "test_bullet.h"
19
20#include "fast_factory.h"
21
22#include "model.h"
23#include "state.h"
24#include "list.h"
25#include "class_list.h"
26
27#include "particle_engine.h"
28#include "particle_emitter.h"
29#include "particle_system.h"
30
31
32using namespace std;
33
34CREATE_FAST_FACTORY_STATIC(TestBullet, CL_TEST_BULLET);
35
36/**
37 *  standard constructor
38*/
39TestBullet::TestBullet () : Projectile()
40{
41  this->setClassID(CL_TEST_BULLET, "TestBullet");
42
43  float modelSize = .3;
44  this->loadModel("models/projectiles/orx-rocket.obj", .3);
45
46  this->energyMin = 1;
47  this->energyMax = 10;
48  this->remove();
49  this->lifeSpan = 2;
50
51  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
52  this->emitter->setParent(this);
53  this->emitter->setSpread(M_PI, M_PI);
54}
55
56
57/**
58 *  standard deconstructor
59*/
60TestBullet::~TestBullet ()
61{
62  // delete this->emitter;
63
64  /* this is normaly done by World.cc by deleting the ParticleEngine */
65  if (TestBullet::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
66  {
67    if (ClassList::exists(TestBullet::trailParticles, CL_PARTICLE_SYSTEM))
68      delete TestBullet::trailParticles;
69    TestBullet::trailParticles = NULL;
70  }
71  if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
72  {
73    if (ClassList::exists(TestBullet::explosionParticles, CL_PARTICLE_SYSTEM))
74      delete TestBullet::explosionParticles;
75    TestBullet::explosionParticles = NULL;
76  }
77
78}
79
80ParticleSystem* TestBullet::trailParticles = NULL;
81ParticleSystem* TestBullet::explosionParticles = NULL;
82
83void TestBullet::activate()
84{
85  State::getWorldEntityList()->add(this);
86  if (unlikely(TestBullet::trailParticles == NULL))
87  {
88    TestBullet::trailParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
89    TestBullet::trailParticles->setName("TestBulletTrailParticles");
90    TestBullet::trailParticles->setLifeSpan(.5, .3);
91    TestBullet::trailParticles->setRadius(0.0, .5);
92    TestBullet::trailParticles->setRadius(0.5, 2.0);
93    TestBullet::trailParticles->setRadius(1.0, 5.0);
94    TestBullet::trailParticles->setColor(0.0, 1,0,0,.7);
95    TestBullet::trailParticles->setColor(0.5, .8,.8,0,.5);
96    TestBullet::trailParticles->setColor(1.0, .7,.7,.7,.0);
97  }
98  if (unlikely(TestBullet::explosionParticles == NULL))
99  {
100    TestBullet::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
101    TestBullet::explosionParticles->setName("TestBulletExplosionParticles");
102    TestBullet::explosionParticles->setLifeSpan(.5, .3);
103    TestBullet::explosionParticles->setRadius(0.0, 10);
104    TestBullet::explosionParticles->setRadius(.5, 20.0);
105    TestBullet::explosionParticles->setRadius(1.0, 3.0);
106    TestBullet::explosionParticles->setColor(0.0, 0,1,0,.9);
107    TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5);
108    TestBullet::explosionParticles->setColor(1.0, 1,1,1,.0);
109  }
110
111  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::trailParticles);
112
113  this->emitter->setEmissionRate(20.0);
114  this->emitter->setEmissionVelocity(3.0);
115}
116
117
118void TestBullet::deactivate()
119{
120  ParticleEngine::getInstance()->breakConnections(this->emitter);
121  this->lifeCycle = 0.0;
122
123//  GarbageCollector::getInstance()->collect(this);
124  State::getWorldEntityList()->remove(this);
125  TestBullet::fastFactory->kill(this);
126}
127
128
129void TestBullet::collidesWith(WorldEntity* entity, const Vector& location)
130{
131  if (this->hitEntity != entity && entity->isA(CL_NPC))
132    this->destroy();
133  this->hitEntity = entity;
134}
135
136/**
137 *  signal tick, time dependent things will be handled here
138 * @param time since last tick
139*/
140void TestBullet::tick (float time)
141{
142  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
143  Vector v = this->velocity * (time);
144  this->shiftCoor(v);
145
146  this->lifeCycle += time/this->lifeSpan;
147  if( this->lifeCycle >= 1.0)
148    {
149      PRINTF(5)("FINALIZE==========================\n");
150      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
151      PRINTF(5)("FINALIZE===========================\n");
152
153      this->deactivate();
154    }
155}
156
157/**
158 *  the function gets called, when the projectile is destroyed
159*/
160void TestBullet::destroy ()
161{
162  PRINTF(5)("DESTROY TestBullet\n");
163  this->lifeCycle = .95; //!< @todo calculate this usefully.
164  ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::trailParticles);
165  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
166
167  this->emitter->setEmissionRate(30.0);
168  this->emitter->setEmissionVelocity(50.0);
169//  this->deactivate();
170
171}
172
173
174void TestBullet::draw () const
175{
176  glMatrixMode(GL_MODELVIEW);
177  glPushMatrix();
178
179  float matrix[4][4];
180  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
181  this->getAbsDir().matrix (matrix);
182  glMultMatrixf((float*)matrix);
183  glScalef(2.0, 2.0, 2.0);
184  this->model->draw();
185
186  glPopMatrix();
187}
188
Note: See TracBrowser for help on using the repository browser.