Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/test_bullet.cc @ 8513

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

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

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