Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: Energy→Health

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