Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

just another upload
GUI seems to work, but there are still some unexplainable segfaults

File size: 5.3 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
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
33#include "weapons/weapon.h"
34#include "../weapons/weapon_manager.h"
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;
62  this->rotationSpeed = 130;
63
64  this->halo = new Billboard();
65  this->halo->setSize(2, 2);
66  this->halo->setTexture("hbolt_halo.png");
67
68  this->weaponMan = new WeaponManager(dynamic_cast<WorldEntity*>(this));
69  this->weaponMan->setParentEntity(this);
70
71  Weapon* cannon = new SpikeLauncher();
72  cannon->setName( "SpikeLauncher");
73  this->weaponMan->addWeapon(cannon, 0, 0);
74  this->weaponMan->changeWeaponConfig(0);
75
76
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);
117  this->rotationVector = VECTOR_RAND(1);
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)){
179    this->weaponMan->fire();
180    this->deactivate();
181  }
182
183  angle += rotationSpeed * dt;
184}
185
186/**
187 *  the function gets called, when the projectile is destroyed
188*/
189void SpikeBall::destroy (WorldEntity* killer)
190{
191  Projectile::destroy( killer );
192  PRINTF(5)("DESTROY SpikeBall\n");
193  this->lifeCycle = .95; //!< @todo calculate this usefully.
194
195  this->emitter->setSystem(SpikeBall::explosionParticles);
196}
197
198
199void SpikeBall::draw () const
200{
201  glPushAttrib(GL_ENABLE_BIT);
202  //glDisable(GL_LIGHTING);
203
204  glMatrixMode(GL_MODELVIEW);
205  glPushMatrix();
206
207  float matrix[4][4];
208  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
209
210  glRotatef(angle, this->rotationVector.x, this->rotationVector.y, this->rotationVector.z);
211  this->getAbsDir().matrix (matrix);
212  glMultMatrixf((float*)matrix);
213  this->getModel()->draw();
214
215  this->halo->draw();
216
217  glPopMatrix();
218
219  glPopAttrib();
220}
221
Note: See TracBrowser for help on using the repository browser.