Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/nadion_blast.cc @ 10769

Last change on this file since 10769 was 10758, checked in by nicolasc, 18 years ago

added shield functionality, reverted paeddae's MP patch - does not work

File size: 5.9 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 Schlumbegrer
13   co-programmer: ..
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "nadion_blast.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "world_entities/npcs/actionbox_enemy.h"
26#include "world_entities/npcs/npc.h"
27
28#include "particles/dot_emitter.h"
29#include "particles/sprite_particles.h"
30
31#include "space_ships/space_ship.h"
32
33#include <cassert>
34#include "debug.h"
35
36#include "static_model.h"
37
38#include "effects/trail.h"
39
40
41
42ObjectListDefinition(NadionBlast);
43CREATE_FAST_FACTORY_STATIC(NadionBlast);
44
45/**
46 *  standard constructor
47*/
48NadionBlast::NadionBlast () : Projectile()
49{
50  this->registerObject(this, NadionBlast::_objectList);
51  this->loadModel("models/projectiles/mbolt.obj",4);
52
53
54  //this->loadModel("models/projectiles/laser.obj");
55
56  this->setMinEnergy(4);
57  this->setHealthMax(0);
58  this->lifeSpan = 2.5;
59  this->angle     = 0;
60
61  this->setDamage(5);
62 
63  //this->emitter = new DotEmitter(1000, 0, 0);
64  this->emitter = new DotEmitter(50, 0, 0);
65  this->emitter->setParent(this);
66  this->emitter->setSpread(M_PI,M_PI);
67  this->emitter->setInheritSpeed(this->velocity.len());
68  this->emitter->setEmissionRate(500.0);
69  this->emitter->setEmissionVelocity(this->velocity.len());
70
71  this->mat = new Material("NadionBlast");
72  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
73  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
74  this->mat->setDiffuse(1,1,1);
75  this->mat->setDiffuseMap("laser_add.png");
76  this->mat->setDiffuseMap("laser2.png",1);
77
78  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat);
79  dynamic_cast<StaticModel*>(this->getModel())->finalize();
80
81  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
82  //this->buildObbTree(4);
83
84//   this->trail = new Trail(6, 4, .1, this);
85  //this->trail->setParent( this);
86//   this->trail->setTexture( "textures/laser.png");
87//   this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0));
88//   this->trail->setAbsCoor(this->getAbsCoor() - this->getVelocity().getNormalized() * .7);
89
90}
91
92
93/**
94 *  standard deconstructor
95 *
96 */
97NadionBlast::~NadionBlast ()
98{
99
100  if (NadionBlast::explosionParticles != NULL && NadionBlast::objectList().size() <= 1)
101  {
102    if (ParticleSystem::objectList().exists(NadionBlast::explosionParticles))
103      delete NadionBlast::explosionParticles;
104    NadionBlast::explosionParticles = NULL;
105    PRINTF(1)("Deleting NadionBlast Explosion Particles\n");
106  }
107
108  delete this->emitter;
109//   delete this->trail;
110}
111
112SpriteParticles* NadionBlast::explosionParticles = NULL;
113
114void NadionBlast::activate()
115{
116//   this->origList = this->getOMListNumber();
117//   this->toList(OM_ENVIRON);
118  if (unlikely(NadionBlast::explosionParticles == NULL))
119  {
120    NadionBlast::explosionParticles = new SpriteParticles(1000);
121    NadionBlast::explosionParticles->setName("NadionBlastExplosionParticles");
122    NadionBlast::explosionParticles->setLifeSpan(.2, .1);
123    NadionBlast::explosionParticles->setRadius(0.0, 10.0);
124    NadionBlast::explosionParticles->setRadius(.5, 6.0);
125    NadionBlast::explosionParticles->setRadius(1.0, 3.0);
126    NadionBlast::explosionParticles->setColor(0.0, 1,1,0,.9);
127    NadionBlast::explosionParticles->setColor(0.5, .8,.8,0,.5);
128    NadionBlast::explosionParticles->setColor(1.0, .8,.8,.7,.0);
129  }
130
131  this->setPhysDamage(10);
132  this->setElecDamage(0);
133  this->setHealth(0);
134
135  this->emitter->setSpread(0);
136  this->emitter->setEmissionRate(10.0);
137  this->emitter->setEmissionVelocity(50);
138}
139
140
141void NadionBlast::deactivate()
142{
143  assert (NadionBlast::explosionParticles != NULL);
144  NadionBlast::explosionParticles->removeEmitter(this->emitter);
145  this->lifeCycle = 0.0;
146
147  this->lifeCycle = 0.0;
148  this->toList(OM_NULL);
149  //this->toList(OM_DEAD);
150//   this->removeNode();
151  NadionBlast::fastFactory->kill(this);
152}
153
154
155// void NadionBlast::hit (float damage, WorldEntity* entity )
156// {
157//
158//   if (this->hitEntity != entity)
159//     this->destroy( entity );
160//   this->hitEntity = entity;
161//  // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
162//   //this->destroy(this);
163//   this->deactivate();
164//
165//   return;
166//
167// }
168
169/**
170 *  signal tick, time dependent things will be handled here
171 * @param dt time since last tick
172*/
173void NadionBlast::tick (float dt)
174{
175  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
176  Vector v = this->velocity * dt;
177  this->shiftCoor(v);
178
179  if (this->tickLifeCycle(dt))
180    this->deactivate();
181
182  this->angle += NadionBlast::rotationSpeed * dt;
183//   this->trail->tick(dt);
184}
185
186/**
187 *  the function gets called, when the projectile is destroyed
188*/
189void NadionBlast::destroy (WorldEntity* killer)
190{
191  //this->deactivate();
192  Projectile::destroy( killer );
193  PRINTF(5)("DESTROY NadionBlast\n");
194  this->lifeCycle = .95; //!< @todo calculate this usefully.
195
196  this->emitter->setSystem(NadionBlast::explosionParticles);
197}
198
199
200void NadionBlast::draw () const
201{
202  glPushAttrib(GL_ENABLE_BIT);
203  glDisable(GL_LIGHTING);
204
205  glPushMatrix();
206  float matrix[4][4];
207  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
208//   glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile
209// HACK, need to be removed, once the AbsDir is correct, replace with the one above
210//   glRotatef(this->angle, this->flightDirection.x, this->flightDirection.y, this->flightDirection.z);
211  this->getAbsDir().matrix (matrix);
212  glMultMatrixf((float*)matrix);
213
214  glScalef(0.75/6, 0.7/16, 0.7/16);  // no double rescale
215
216  this->mat->select();
217  dynamic_cast<StaticModel*>(this->getModel())->draw();
218  this->mat->unselect();
219//   glScalef(4/.75,16/.7,16/.7);
220//   glTranslatef(-3,0,0);
221//   this->trail->draw();
222  glPopMatrix();
223  glPopAttrib();
224
225}
Note: See TracBrowser for help on using the repository browser.