Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

R playability/src/world_entities/projectiles/hbolt.cc
R playability/src/world_entities/projectiles/hbolt.h

File size: 4.7 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 "static_model.h"
30
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");
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->mat = new Material("hBolt_halo");
59  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
60  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
61  this->mat->setDiffuse(1,1,1);
62/*  this->mat->setDiffuseMap("hbolt.png");
63  this->mat->setDiffuseMap("hbolt.png",1);
64  this->mat->setDiffuseMap("hbolt_halo.png",1);
65  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
66  dynamic_cast<StaticModel*>(this->getModel())->finalize();*/
67
68}
69
70
71/**
72 *  standard deconstructor
73*/
74HBolt::~HBolt ()
75{
76  // delete this->emitter;
77
78  /* this is normaly done by World.cc by deleting the ParticleEngine */
79  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
80  {
81    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
82    //  delete HBolt::explosionParticles;
83    PRINTF(1)("Deleting HBolt Particles\n");
84    HBolt::explosionParticles = NULL;
85  }
86
87}
88
89SpriteParticles* HBolt::explosionParticles = NULL;
90
91void HBolt::activate()
92{
93  if (unlikely(HBolt::explosionParticles == NULL))
94  {
95    HBolt::explosionParticles = new SpriteParticles(1000);
96    HBolt::explosionParticles->setName("HBoltExplosionParticles");
97    HBolt::explosionParticles->setLifeSpan(.5, .3);
98    HBolt::explosionParticles->setRadius(0.0, 10.0);
99    HBolt::explosionParticles->setRadius(.5, 6.0);
100    HBolt::explosionParticles->setRadius(1.0, 3.0);
101    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
102    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
103    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
104  }
105
106  this->setDamage(100);
107  this->setHealth(0);
108}
109
110
111void HBolt::deactivate()
112{
113  assert (HBolt::explosionParticles != NULL);
114  HBolt::explosionParticles->removeEmitter(this->emitter);
115  this->lifeCycle = 0.0;
116
117  this->toList(OM_NULL);
118  this->removeNode();
119  HBolt::fastFactory->kill(this);
120}
121
122
123void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
124{
125  if (this->hitEntity != entity && entity->isA(CL_NPC))
126    this->destroy( entity );
127  this->hitEntity = entity;
128}
129
130
131void HBolt::updateAngle (float time)
132{
133  this->angle += this->rotationSpeed * time;
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  //float w = this->rotationSpeed * M_PI;
151  //Quaternion rotation(this->rotationSpeed * dt, this->axis);
152  //Quaternion u = this->getRelDir();
153  //this->setRelDir(u * rotation);
154
155  this->updateAngle(dt);
156
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  glMatrixMode(GL_MODELVIEW);
176  glPushMatrix();
177
178
179  glTranslatef (this->getAbsCoor ().x,
180                  this->getAbsCoor ().y,
181                  this->getAbsCoor ().z);
182  Vector tmpRot = this->getAbsDir().getSpacialAxis();
183  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
184  glRotatef(this->angle, 0.0, 0.0, 1.0);
185
186  this->getModel()->draw();
187
188/*
189  this->mat->select();
190  dynamic_cast<StaticModel*>(this->getModel())->draw();
191  this->mat->select();
192  dynamic_cast<StaticModel*>(this->getModel())->draw();
193  this->mat->unselect();
194  this->mat->unselect();*/
195
196  glPopMatrix();
197}
Note: See TracBrowser for help on using the repository browser.