Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10224 was 10224, checked in by nicolasc, 14 years ago

bump

File size: 5.5 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  this->weaponMan->setSlotCount(1);
71  this->weaponMan->setSlotPosition(0, Vector(0, 0, 0));
72  this->weaponMan->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
73
74  Weapon* cannon = new SpikeLauncher();
75  cannon->setName( "SpikeLauncher");
76  this->weaponMan->addWeapon(cannon, 0, 0);
77  this->weaponMan->changeWeaponConfig(0);
78}
79
80
81/**
82 *  standard deconstructor
83*/
84SpikeBall::~SpikeBall ()
85{
86  // delete this->emitter;
87
88  /* this is normaly done by World.cc by deleting the ParticleEngine */
89  if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1)
90  {
91    //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM))
92    //  delete SpikeBall::explosionParticles;
93    PRINTF(1)("Deleting SpikeBall Particles\n");
94    SpikeBall::explosionParticles = NULL;
95  }
96
97}
98
99SpriteParticles* SpikeBall::explosionParticles = NULL;
100
101void SpikeBall::activate()
102{
103  if (unlikely(SpikeBall::explosionParticles == NULL))
104  {
105    SpikeBall::explosionParticles = new SpriteParticles(1000);
106    SpikeBall::explosionParticles->setName("BoltExplosionParticles");
107    SpikeBall::explosionParticles->setLifeSpan(.5, .3);
108    SpikeBall::explosionParticles->setRadius(0.0, 10.0);
109    SpikeBall::explosionParticles->setRadius(.5, 6.0);
110    SpikeBall::explosionParticles->setRadius(1.0, 3.0);
111    SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9);
112    SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5);
113    SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0);
114  }
115
116  this->setDamage(5);
117  this->setHealth(0);
118  this->rotationVector = VECTOR_RAND(1);
119}
120
121
122void SpikeBall::deactivate()
123{
124  assert (SpikeBall::explosionParticles != NULL);
125  SpikeBall::explosionParticles->removeEmitter(this->emitter);
126  this->lifeCycle = 0.0;
127
128  this->toList(OM_NULL);
129  this->removeNode();
130  SpikeBall::fastFactory->kill(this);
131}
132
133
134void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location)
135{
136  PRINTF(0)("Collision with SpikeBall\n");
137  if (this->hitEntity != entity && entity->isA(CL_NPC))
138    this->destroy( entity );
139  this->hitEntity = entity;
140  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
141//   this->deactivate();
142}
143/*
144void SpikeBall::blow()
145{
146  const float* v = this->getModel()->getVertexArray();
147  Projectile* pj = NULL;
148
149  for (unsigned int i = 0; i < this->getModel()->getVertexCount(); i++)
150  {
151
152//     v = this->getModel()->getModelInfo
153
154      pj  = this->getProjectile();
155      if (pj == NULL)
156        return;
157
158      if (v[i].x * v[i].x + v[i].y * v[i].y + v[i].z * v[i].z > 4)
159      {
160        pj->setParent(PNode::getNullParent());
161        pj->setAbsCoor(this->getAbsCoor() + v);
162        pj->setAbsDir(v->getNormalized() * this->speed);
163        pj->activate();
164      }
165  }
166}*/
167
168
169/**
170 *  signal tick, time dependent things will be handled here
171 * @param dt time since last tick
172*/
173void SpikeBall::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->lifeCycle > .9){
180    printf("called by spikeball  ");
181    this->weaponMan->fire();
182  }
183
184  if (this->tickLifeCycle(dt))
185      this->deactivate();
186
187  angle += rotationSpeed * dt;
188}
189
190/**
191 *  the function gets called, when the projectile is destroyed
192*/
193void SpikeBall::destroy (WorldEntity* killer)
194{
195  Projectile::destroy( killer );
196  PRINTF(5)("DESTROY SpikeBall\n");
197  this->lifeCycle = .95; //!< @todo calculate this usefully.
198
199  this->emitter->setSystem(SpikeBall::explosionParticles);
200}
201
202
203void SpikeBall::draw () const
204{
205  glPushAttrib(GL_ENABLE_BIT);
206  //glDisable(GL_LIGHTING);
207
208  glMatrixMode(GL_MODELVIEW);
209  glPushMatrix();
210
211  float matrix[4][4];
212  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
213
214  glRotatef(angle, this->rotationVector.x, this->rotationVector.y, this->rotationVector.z);
215  this->getAbsDir().matrix (matrix);
216  glMultMatrixf((float*)matrix);
217  this->getModel()->draw();
218
219  this->halo->draw();
220
221  glPopMatrix();
222
223  glPopAttrib();
224}
225
Note: See TracBrowser for help on using the repository browser.