Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/hbolt.cc @ 10180

Last change on this file since 10180 was 10180, checked in by nicolasc, 14 years ago

bump

File size: 4.3 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004-2006 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: Nicolas Schlumberger, Marc Schaerrer
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
29// #include "effects/billboard.h"
30#include "space_ships/space_ship.h"
31
32#include "class_id_DEPRECATED.h"
33ObjectListDefinition(HBolt);
34CREATE_FAST_FACTORY_STATIC(HBolt);
35
36/**
37 *  standard constructor
38*/
39HBolt::HBolt () : Projectile()
40{
41  this->registerObject(this, HBolt::_objectList);
42
43  this->loadModel("models/projectiles/hbolt.obj",1.1);
44
45  this->setMinEnergy(10);
46  this->setHealthMax(0);
47  this->lifeSpan = 7.0;
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
58  this->halo = new Billboard();
59  this->halo->setSize(.65, .65);
60  this->halo->setTexture("hbolt_halo2.png");
61}
62
63
64/**
65 *  standard deconstructor
66*/
67HBolt::~HBolt ()
68{
69  // delete this->emitter;
70
71  /* this is normaly done by World.cc by deleting the ParticleEngine */
72  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
73  {
74    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
75    //  delete HBolt::explosionParticles;
76    PRINTF(1)("Deleting HBolt Particles\n");
77    HBolt::explosionParticles = NULL;
78  }
79
80}
81
82SpriteParticles* HBolt::explosionParticles = NULL;
83
84void HBolt::activate()
85{
86  if (unlikely(HBolt::explosionParticles == NULL))
87  {
88    HBolt::explosionParticles = new SpriteParticles(1000);
89    HBolt::explosionParticles->setName("HBoltExplosionParticles");
90    HBolt::explosionParticles->setLifeSpan(.5, .3);
91    HBolt::explosionParticles->setRadius(0.0, 10.0);
92    HBolt::explosionParticles->setRadius(.5, 6.0);
93    HBolt::explosionParticles->setRadius(1.0, 3.0);
94    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
95    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
96    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
97  }
98
99  this->setPhysDamage(100);
100  this->setHealth(0);
101}
102
103
104void HBolt::deactivate()
105{
106  assert (HBolt::explosionParticles != NULL);
107  HBolt::explosionParticles->removeEmitter(this->emitter);
108  this->lifeCycle = 0.0;
109
110  this->toList(OM_NULL);
111  this->removeNode();
112  HBolt::fastFactory->kill(this);
113}
114
115/*
116void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
117{
118  printf("Collision with HBolt\n");
119  if (this->hitEntity != entity && entity->isA(CL_NPC) || entity == this->target)
120    this->destroy( entity );
121  this->hitEntity = entity;
122  dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage());
123  this->deactivate();
124}*/
125
126
127/**
128 *  signal tick, time dependent things will be handled here
129 * @param dt time since last tick
130*/
131void HBolt::tick (float dt)
132{
133  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
134  Vector v = this->velocity * dt;
135  this->shiftCoor(v);
136
137  if (this->tickLifeCycle(dt))
138    this->deactivate();
139
140  this->angle += this->rotationSpeed * dt;
141
142
143}
144
145/**
146 *  the function gets called, when the projectile is destroyed
147*/
148void HBolt::destroy (WorldEntity* killer)
149{
150  Projectile::destroy( killer );
151  PRINTF(5)("DESTROY HBolt\n");
152  this->lifeCycle = .95; //!< @todo calculate this usefully.
153
154  this->emitter->setSystem(HBolt::explosionParticles);
155}
156
157
158void HBolt::draw () const
159{
160
161  glPushAttrib(GL_ENABLE_BIT);
162  glDisable(GL_LIGHTING);
163  glDisable(GL_FOG);
164
165  glMatrixMode(GL_MODELVIEW);
166  glPushMatrix();
167
168
169  glTranslatef (this->getAbsCoor ().x,
170                  this->getAbsCoor ().y,
171                  this->getAbsCoor ().z);
172
173  this->halo->draw();
174
175  Vector tmpRot = this->getAbsDir().getSpacialAxis();
176  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
177  glRotatef(this->angle, 0.0, 0.0, 1.0);
178
179  this->getModel()->draw();
180
181  glPopMatrix();
182  glPopAttrib();
183
184}
Note: See TracBrowser for help on using the repository browser.