Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

inital upload of projectile_weapon, started usage in spike_ball

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