Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/hbolt.cc @ 9998

Last change on this file since 9998 was 9998, checked in by marcscha, 17 years ago

multiple weapons, crosshair visibility → changelog

File size: 4.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Patrick Boenzli
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "hbolt.h"
19
20#include "state.h"
21#include "model.h"
22
23#include "particles/dot_emitter.h"
24#include "particles/sprite_particles.h"
25
26#include <cassert>
27#include "debug.h"
28
29
30#include "class_id_DEPRECATED.h"
31ObjectListDefinition(HBolt);
32CREATE_FAST_FACTORY_STATIC(HBolt);
33
34/**
35 *  standard constructor
36*/
37HBolt::HBolt () : Projectile()
38{
39  this->registerObject(this, HBolt::_objectList);
40
41  this->loadModel("models/projectiles/hbolt.obj");
42
43  this->setMinEnergy(20);
44  this->setHealthMax(0);
45  this->lifeSpan = 5.0;
46
47  this->angle = 0;
48  this->rotationSpeed = 3;
49
50  this->emitter = new DotEmitter(100, 5, M_2_PI);
51  this->emitter->setParent(this);
52  this->emitter->setSpread(M_PI, M_PI);
53  this->emitter->setEmissionRate(300.0);
54  this->emitter->setEmissionVelocity(50.0);
55}
56
57
58/**
59 *  standard deconstructor
60*/
61HBolt::~HBolt ()
62{
63  // delete this->emitter;
64
65  /* this is normaly done by World.cc by deleting the ParticleEngine */
66  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
67  {
68    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
69    //  delete HBolt::explosionParticles;
70    PRINTF(1)("Deleting HBolt Particles\n");
71    HBolt::explosionParticles = NULL;
72  }
73
74}
75
76SpriteParticles* HBolt::explosionParticles = NULL;
77
78void HBolt::activate()
79{
80  if (unlikely(HBolt::explosionParticles == NULL))
81  {
82    HBolt::explosionParticles = new SpriteParticles(1000);
83    HBolt::explosionParticles->setName("HBoltExplosionParticles");
84    HBolt::explosionParticles->setLifeSpan(.5, .3);
85    HBolt::explosionParticles->setRadius(0.0, 10.0);
86    HBolt::explosionParticles->setRadius(.5, 6.0);
87    HBolt::explosionParticles->setRadius(1.0, 3.0);
88    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
89    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
90    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
91  }
92
93  this->setDamage(100);
94  this->setHealth(0);
95}
96
97
98void HBolt::deactivate()
99{
100  assert (HBolt::explosionParticles != NULL);
101  HBolt::explosionParticles->removeEmitter(this->emitter);
102  this->lifeCycle = 0.0;
103
104  this->toList(OM_NULL);
105  this->removeNode();
106  HBolt::fastFactory->kill(this);
107}
108
109
110void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
111{
112  if (this->hitEntity != entity && entity->isA(CL_NPC))
113    this->destroy( entity );
114  this->hitEntity = entity;
115}
116
117
118void HBolt::updateAngle ()
119{
120  this->angle = this->angle + this->rotationSpeed;
121}
122
123
124/**
125 *  signal tick, time dependent things will be handled here
126 * @param dt time since last tick
127*/
128void HBolt::tick (float dt)
129{
130  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
131  Vector v = this->velocity * dt;
132  this->shiftCoor(v);
133
134  if (this->tickLifeCycle(dt))
135    this->deactivate();
136
137  this->updateAngle();
138
139}
140
141/**
142 *  the function gets called, when the projectile is destroyed
143*/
144void HBolt::destroy (WorldEntity* killer)
145{
146  Projectile::destroy( killer );
147  PRINTF(5)("DESTROY HBolt\n");
148  this->lifeCycle = .95; //!< @todo calculate this usefully.
149
150  this->emitter->setSystem(HBolt::explosionParticles);
151}
152
153
154void HBolt::draw () //const
155{
156  glPushAttrib(GL_ENABLE_BIT);
157  glDisable(GL_LIGHTING);
158
159  glMatrixMode(GL_MODELVIEW);
160  glPushMatrix();
161
162/*  float matrix[4][4];
163  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
164  this->getAbsDir().matrix (matrix);
165  glMultMatrixf((float*)matrix);
166  glScalef(2.0, 2.0, 2.0);
167  this->getModel()->draw();
168  glPopMatrix();*/
169
170  //this->updateAngle();
171
172  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
173  glRotatef(this->angle, 0.0, 0.0, -1.0);
174  //this->getModel()->draw();
175  WorldEntity::draw();
176  glPopMatrix();
177  glPopAttrib();
178}
179
Note: See TracBrowser for help on using the repository browser.