Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/bolt.cc @ 10038

Last change on this file since 10038 was 9998, checked in by marcscha, 18 years ago

multiple weapons, crosshair visibility → changelog

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