Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5875 was 5779, checked in by bensch, 19 years ago

orxonox/trunk: ClassList is now in std::list style
ShellCommand is now in std::list style

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