Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/world_entities/projectiles/test_bullet.cc @ 7679

Last change on this file since 7679 was 7193, checked in by bensch, 19 years ago

orxonox/trunk: new style for resources (prework/movement)

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