Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/hbolt.cc @ 10511

Last change on this file since 10511 was 10511, checked in by snellen, 17 years ago

corrected typo in worldentity → setVisibiliy to setVisibility

File size: 4.9 KB
RevLine 
[10047]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[10104]4   Copyright (C) 2004-2006 orx
[10047]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
[10104]12   main-programmer: Nicolas Schlumberger, Marc Schaerrer
[10047]13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "hbolt.h"
19
20#include "state.h"
21#include "model.h"
22
23#include "particles/dot_emitter.h"
24#include "particles/sprite_particles.h"
25
26#include <cassert>
27#include "debug.h"
28
[10074]29// #include "effects/billboard.h"
[10079]30#include "space_ships/space_ship.h"
[10366]31#include "npcs/npc.h"
[10047]32
33ObjectListDefinition(HBolt);
34CREATE_FAST_FACTORY_STATIC(HBolt);
35
36/**
37 *  standard constructor
38*/
39HBolt::HBolt () : Projectile()
40{
41  this->registerObject(this, HBolt::_objectList);
42
[10072]43  this->loadModel("models/projectiles/hbolt.obj",1.1);
[10047]44
45  this->setMinEnergy(10);
46  this->setHealthMax(0);
[10274]47  this->lifeSpan = 2.0;
[10047]48
49  this->angle = 0;
50  this->rotationSpeed = 600;
51
52  this->emitter = new DotEmitter(100, 5, M_2_PI);
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
[10063]58  this->halo = new Billboard();
59  this->halo->setSize(.65, .65);
60  this->halo->setTexture("hbolt_halo2.png");
[10511]61  this->halo->setVisibility(false);
[10345]62
[10047]63}
64
65
66/**
67 *  standard deconstructor
68*/
69HBolt::~HBolt ()
70{
71  // delete this->emitter;
72
73  /* this is normaly done by World.cc by deleting the ParticleEngine */
74  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
75  {
76    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
77    //  delete HBolt::explosionParticles;
78    PRINTF(1)("Deleting HBolt Particles\n");
79    HBolt::explosionParticles = NULL;
80  }
81
82}
83
84SpriteParticles* HBolt::explosionParticles = NULL;
85
86void HBolt::activate()
87{
[10511]88  this->halo->setVisibility(true);
[10345]89  this->origList = this->getOMListNumber();
[10274]90  this->toList(OM_ENVIRON);
[10047]91  if (unlikely(HBolt::explosionParticles == NULL))
92  {
93    HBolt::explosionParticles = new SpriteParticles(1000);
94    HBolt::explosionParticles->setName("HBoltExplosionParticles");
95    HBolt::explosionParticles->setLifeSpan(.5, .3);
96    HBolt::explosionParticles->setRadius(0.0, 10.0);
97    HBolt::explosionParticles->setRadius(.5, 6.0);
98    HBolt::explosionParticles->setRadius(1.0, 3.0);
99    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
100    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
101    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
102  }
103
[10079]104  this->setPhysDamage(100);
[10047]105  this->setHealth(0);
106}
107
108
109void HBolt::deactivate()
110{
[10511]111  this->halo->setVisibility(false);
[10047]112  assert (HBolt::explosionParticles != NULL);
113  HBolt::explosionParticles->removeEmitter(this->emitter);
114  this->lifeCycle = 0.0;
115
[10274]116  this->toList(OM_DEAD);
[10047]117  this->removeNode();
118  HBolt::fastFactory->kill(this);
[10274]119
[10047]120}
121
[10261]122
[10274]123void HBolt::hit (float damage, WorldEntity* entity )
[10047]124{
[10104]125  printf("Collision with HBolt\n");
[10366]126  if (this->hitEntity != entity && entity->isA(NPC::staticClassID()) || entity == this->target)
[10047]127    this->destroy( entity );
128  this->hitEntity = entity;
[10261]129 // dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage());
[10109]130  this->deactivate();
[10261]131}
[10047]132
133
134/**
135 *  signal tick, time dependent things will be handled here
136 * @param dt time since last tick
137*/
138void HBolt::tick (float dt)
139{
140  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
141  Vector v = this->velocity * dt;
142  this->shiftCoor(v);
143
144  if (this->tickLifeCycle(dt))
145    this->deactivate();
146
[10104]147  this->angle += this->rotationSpeed * dt;
[10047]148
[10274]149  for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++)
150  {
[10345]151    if( ((*eIterator)->getOMListNumber() != (this->origList -1))   && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8)
[10274]152    {
153      (*eIterator)->hit (this->getDamage(),this);
154      this->deactivate();
155  PRINTF(0)("HBolt destroyed\n");
156    }
157  }
[10047]158}
159
160/**
161 *  the function gets called, when the projectile is destroyed
162*/
163void HBolt::destroy (WorldEntity* killer)
164{
165  Projectile::destroy( killer );
166  PRINTF(5)("DESTROY HBolt\n");
167  this->lifeCycle = .95; //!< @todo calculate this usefully.
168
169  this->emitter->setSystem(HBolt::explosionParticles);
170}
171
172
173void HBolt::draw () const
174{
175
[10159]176  glPushAttrib(GL_ENABLE_BIT);
177  glDisable(GL_LIGHTING);
178  glDisable(GL_FOG);
179
[10047]180  glMatrixMode(GL_MODELVIEW);
181  glPushMatrix();
182
183
184  glTranslatef (this->getAbsCoor ().x,
185                  this->getAbsCoor ().y,
186                  this->getAbsCoor ().z);
[10063]187
188  this->halo->draw();
189
[10047]190  Vector tmpRot = this->getAbsDir().getSpacialAxis();
191  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
192  glRotatef(this->angle, 0.0, 0.0, 1.0);
193
[10074]194  this->getModel()->draw();
[10047]195
196  glPopMatrix();
[10159]197  glPopAttrib();
198
[10047]199}
Note: See TracBrowser for help on using the repository browser.