Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

cleaned out origList

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