Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6693 was 6692, checked in by patrick, 19 years ago

emerged spaceshipcontrol back to trunk via command >svn merge branches/spaceshipcontrol/ trunk/ -r 6639:HEAD

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