Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/projectiles/test_bullet.cc @ 10663

Last change on this file since 10663 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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