Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/laser.cc @ 6701

Last change on this file since 6701 was 6700, checked in by bensch, 19 years ago

trunk: Energy→Health

File size: 3.6 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 "laser.h"
19#include <assert.h>
20
21
22#include "fast_factory.h"
23
24#include "state.h"
25#include "class_list.h"
26#include "model.h"
27
28#include "particle_emitter.h"
29#include "sprite_particles.h"
30#include <cassert>
31
32#include "assert.h"
33
34
35using namespace std;
36
37CREATE_FAST_FACTORY_STATIC(Laser, CL_LASER);
38
39/**
40 *  standard constructor
41*/
42Laser::Laser () : Projectile()
43{
44  this->setClassID(CL_LASER, "Laser");
45
46  this->loadModel("models/projectiles/laser.obj");
47
48  this->setMinEnergy(1);
49  this->setHealthMax(10);
50  this->lifeSpan = 5.0;
51
52  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
53  this->emitter->setParent(this);
54  this->emitter->setSpread(M_PI, M_PI);
55  this->emitter->setEmissionRate(300.0);
56  this->emitter->setEmissionVelocity(50.0);
57}
58
59
60/**
61 *  standard deconstructor
62*/
63Laser::~Laser ()
64{
65  // delete this->emitter;
66
67  /* this is normaly done by World.cc by deleting the ParticleEngine */
68  if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 1)
69  {
70    //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM))
71    //  delete Laser::explosionParticles;
72    PRINTF(1)("Deleting Laser Particles\n");
73    Laser::explosionParticles = NULL;
74  }
75
76}
77
78SpriteParticles* Laser::explosionParticles = NULL;
79
80void Laser::activate()
81{
82  if (unlikely(Laser::explosionParticles == NULL))
83  {
84    Laser::explosionParticles = new SpriteParticles(1000);
85    Laser::explosionParticles->setName("LaserExplosionParticles");
86    Laser::explosionParticles->setLifeSpan(.5, .3);
87    Laser::explosionParticles->setRadius(0.0, 10.0);
88    Laser::explosionParticles->setRadius(.5, 6.0);
89    Laser::explosionParticles->setRadius(1.0, 3.0);
90    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
91    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
92    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
93  }
94}
95
96
97void Laser::deactivate()
98{
99  assert (Laser::explosionParticles != NULL);
100  Laser::explosionParticles->removeEmitter(this->emitter);
101  this->lifeCycle = 0.0;
102
103  this->toList(OM_NULL);
104  this->removeNode();
105  Laser::fastFactory->kill(this);
106}
107
108
109void Laser::collidesWith(WorldEntity* entity, const Vector& location)
110{
111  if (this->hitEntity != entity && entity->isA(CL_NPC))
112    this->destroy();
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 Laser::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 Laser::destroy ()
134{
135  PRINTF(5)("DESTROY Laser\n");
136  this->lifeCycle = .95; //!< @todo calculate this usefully.
137
138  this->emitter->setSystem(Laser::explosionParticles);
139}
140
141
142void Laser::draw () const
143{
144  glMatrixMode(GL_MODELVIEW);
145  glPushMatrix();
146  glPushAttrib(GL_ENABLE_BIT);
147  glDisable(GL_LIGHTING);
148
149  float matrix[4][4];
150  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
151  this->getAbsDir().matrix (matrix);
152  glMultMatrixf((float*)matrix);
153  glScalef(2.0, 2.0, 2.0);
154  this->getModel()->draw();
155  glPopAttrib();
156  glPopMatrix();
157}
158
Note: See TracBrowser for help on using the repository browser.