Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/hbolt.cc @ 10737

Last change on this file since 10737 was 10737, checked in by nicolasc, 17 years ago

collision fix

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