Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/spike_ball.cc @ 10217

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

bump

File size: 5.4 KB
RevLine 
[10170]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
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "spike_ball.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "particles/dot_emitter.h"
26#include "particles/sprite_particles.h"
27
28#include <cassert>
29#include "debug.h"
30
31#include "space_ships/space_ship.h"
32
[10180]33#include "weapons/weapon.h"
[10196]34#include "../weapons/weapon_manager.h"
[10170]35
36#include "class_id_DEPRECATED.h"
37ObjectListDefinition(SpikeBall);
38CREATE_FAST_FACTORY_STATIC(SpikeBall);
39
40/**
41 *  standard constructor
42*/
43SpikeBall::SpikeBall () : Projectile()
44{
45  this->registerObject(this, SpikeBall::_objectList);
46
47  this->loadModel("models/projectiles/spike_ball.obj", .25);
48
49  this->setMinEnergy(1);
50  this->setHealthMax(0);
51  this->lifeSpan = 1.0;
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->speed = 150;
60
61  this->angle = 0;
[10188]62  this->rotationSpeed = 130;
63
64  this->halo = new Billboard();
65  this->halo->setSize(2, 2);
66  this->halo->setTexture("hbolt_halo.png");
67
[10196]68  this->weaponMan = new WeaponManager(dynamic_cast<WorldEntity*>(this));
69  this->weaponMan->setParentEntity(this);
70
[10188]71  Weapon* cannon = new SpikeLauncher();
72  cannon->setName( "SpikeLauncher");
[10196]73  this->weaponMan->addWeapon(cannon, 0, 0);
74  this->weaponMan->changeWeaponConfig(0);
[10188]75
[10217]76  this->ttd = false;
[10170]77}
78
79
80/**
81 *  standard deconstructor
82*/
83SpikeBall::~SpikeBall ()
84{
85  // delete this->emitter;
86
87  /* this is normaly done by World.cc by deleting the ParticleEngine */
88  if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1)
89  {
90    //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM))
91    //  delete SpikeBall::explosionParticles;
92    PRINTF(1)("Deleting SpikeBall Particles\n");
93    SpikeBall::explosionParticles = NULL;
94  }
95
96}
97
98SpriteParticles* SpikeBall::explosionParticles = NULL;
99
100void SpikeBall::activate()
101{
102  if (unlikely(SpikeBall::explosionParticles == NULL))
103  {
104    SpikeBall::explosionParticles = new SpriteParticles(1000);
105    SpikeBall::explosionParticles->setName("BoltExplosionParticles");
106    SpikeBall::explosionParticles->setLifeSpan(.5, .3);
107    SpikeBall::explosionParticles->setRadius(0.0, 10.0);
108    SpikeBall::explosionParticles->setRadius(.5, 6.0);
109    SpikeBall::explosionParticles->setRadius(1.0, 3.0);
110    SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9);
111    SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5);
112    SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0);
113  }
114
115  this->setDamage(5);
116  this->setHealth(0);
[10188]117  this->rotationVector = VECTOR_RAND(1);
[10170]118}
119
120
121void SpikeBall::deactivate()
122{
123  assert (SpikeBall::explosionParticles != NULL);
124  SpikeBall::explosionParticles->removeEmitter(this->emitter);
125  this->lifeCycle = 0.0;
126
127  this->toList(OM_NULL);
128  this->removeNode();
129  SpikeBall::fastFactory->kill(this);
130}
131
132
133void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location)
134{
135  PRINTF(0)("Collision with SpikeBall\n");
136  if (this->hitEntity != entity && entity->isA(CL_NPC))
137    this->destroy( entity );
138  this->hitEntity = entity;
139  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
140//   this->deactivate();
141}
142/*
143void SpikeBall::blow()
144{
145  const float* v = this->getModel()->getVertexArray();
146  Projectile* pj = NULL;
147
148  for (unsigned int i = 0; i < this->getModel()->getVertexCount(); i++)
149  {
150
151//     v = this->getModel()->getModelInfo
152
153      pj  = this->getProjectile();
154      if (pj == NULL)
155        return;
156
157      if (v[i].x * v[i].x + v[i].y * v[i].y + v[i].z * v[i].z > 4)
158      {
159        pj->setParent(PNode::getNullParent());
160        pj->setAbsCoor(this->getAbsCoor() + v);
161        pj->setAbsDir(v->getNormalized() * this->speed);
162        pj->activate();
163      }
164  }
165}*/
166
167
168/**
169 *  signal tick, time dependent things will be handled here
170 * @param dt time since last tick
171*/
172void SpikeBall::tick (float dt)
173{
174  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
175  Vector v = this->velocity * dt;
176  this->shiftCoor(v);
177
178  if (this->tickLifeCycle(dt)){
[10217]179    this->weaponMan->getWeapon(0)->requestAction(WA_SHOOT);
180    if (this->ttd)
181      this->deactivate();
182    this->ttd = true;
[10170]183  }
184
185  angle += rotationSpeed * dt;
186}
187
188/**
189 *  the function gets called, when the projectile is destroyed
190*/
191void SpikeBall::destroy (WorldEntity* killer)
192{
193  Projectile::destroy( killer );
194  PRINTF(5)("DESTROY SpikeBall\n");
195  this->lifeCycle = .95; //!< @todo calculate this usefully.
196
197  this->emitter->setSystem(SpikeBall::explosionParticles);
198}
199
200
201void SpikeBall::draw () const
202{
203  glPushAttrib(GL_ENABLE_BIT);
204  //glDisable(GL_LIGHTING);
205
206  glMatrixMode(GL_MODELVIEW);
207  glPushMatrix();
208
209  float matrix[4][4];
210  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
211
[10188]212  glRotatef(angle, this->rotationVector.x, this->rotationVector.y, this->rotationVector.z);
[10170]213  this->getAbsDir().matrix (matrix);
214  glMultMatrixf((float*)matrix);
215  this->getModel()->draw();
216
217  this->halo->draw();
218
219  glPopMatrix();
220
221  glPopAttrib();
222}
223
Note: See TracBrowser for help on using the repository browser.