Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10087 was 10081, checked in by marcscha, 18 years ago

Some surprises for comming wednesday

File size: 4.4 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 "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
33#include "class_id_DEPRECATED.h"
34ObjectListDefinition(HBolt);
35CREATE_FAST_FACTORY_STATIC(HBolt);
36
37/**
38 *  standard constructor
39*/
40HBolt::HBolt () : Projectile()
41{
42  this->registerObject(this, HBolt::_objectList);
43
44  this->loadModel("models/projectiles/hbolt.obj",1.1);
45
46  this->setMinEnergy(10);
47  this->setHealthMax(0);
48  this->lifeSpan = 7.0;
49
50  this->angle = 0;
51  this->rotationSpeed = 600;
52
53  this->emitter = new DotEmitter(100, 5, M_2_PI);
54  this->emitter->setParent(this);
55  this->emitter->setSpread(M_PI, M_PI);
56  this->emitter->setEmissionRate(300.0);
57  this->emitter->setEmissionVelocity(50.0);
58
59  this->halo = new Billboard();
60  this->halo->setSize(.65, .65);
61  this->halo->setTexture("hbolt_halo2.png");
62
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{
88  if (unlikely(HBolt::explosionParticles == NULL))
89  {
90    HBolt::explosionParticles = new SpriteParticles(1000);
91    HBolt::explosionParticles->setName("HBoltExplosionParticles");
92    HBolt::explosionParticles->setLifeSpan(.5, .3);
93    HBolt::explosionParticles->setRadius(0.0, 10.0);
94    HBolt::explosionParticles->setRadius(.5, 6.0);
95    HBolt::explosionParticles->setRadius(1.0, 3.0);
96    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
97    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
98    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
99  }
100
101  this->setPhysDamage(100);
102  this->setHealth(0);
103}
104
105
106void HBolt::deactivate()
107{
108  assert (HBolt::explosionParticles != NULL);
109  HBolt::explosionParticles->removeEmitter(this->emitter);
110  this->lifeCycle = 0.0;
111
112  this->toList(OM_NULL);
113  this->removeNode();
114  HBolt::fastFactory->kill(this);
115}
116
117
118void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
119{
120  PRINTF(0)("Collision with HBolt\n");
121  if (this->hitEntity != entity && entity->isA(CL_NPC))
122    this->destroy( entity );
123  this->hitEntity = entity;
124  dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage());
125  this->deactivate();
126}
127
128
129void HBolt::updateAngle (float time)
130{
131  this->angle += this->rotationSpeed * time;
132}
133
134
135/**
136 *  signal tick, time dependent things will be handled here
137 * @param dt time since last tick
138*/
139void HBolt::tick (float dt)
140{
141  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
142  Vector v = this->velocity * dt;
143  this->shiftCoor(v);
144
145  if (this->tickLifeCycle(dt))
146    this->deactivate();
147
148  this->updateAngle(dt);
149
150
151}
152
153/**
154 *  the function gets called, when the projectile is destroyed
155*/
156void HBolt::destroy (WorldEntity* killer)
157{
158  Projectile::destroy( killer );
159  PRINTF(5)("DESTROY HBolt\n");
160  this->lifeCycle = .95; //!< @todo calculate this usefully.
161
162  this->emitter->setSystem(HBolt::explosionParticles);
163}
164
165
166void HBolt::draw () const
167{
168
169  glMatrixMode(GL_MODELVIEW);
170  glPushMatrix();
171
172
173  glTranslatef (this->getAbsCoor ().x,
174                  this->getAbsCoor ().y,
175                  this->getAbsCoor ().z);
176
177  this->halo->draw();
178
179  Vector tmpRot = this->getAbsDir().getSpacialAxis();
180  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
181  glRotatef(this->angle, 0.0, 0.0, 1.0);
182
183  this->getModel()->draw();
184
185//   this->mat->select();
186/*   dynamic_cast<StaticModel*>(this->getModel())->draw();*/
187//   this->mat->select();
188//   dynamic_cast<StaticModel*>(this->getModel())->draw();
189//   this->mat->unselect();
190
191
192  glPopMatrix();
193}
Note: See TracBrowser for help on using the repository browser.