Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/weapons/laser.cc @ 6284

Last change on this file since 6284 was 6222, checked in by bensch, 19 years ago

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

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