Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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