Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

update regen(); add new model for hbolt

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");   //!< Model not yet in repo
42
43  this->setMinEnergy(10);
44  this->setHealthMax(0);
45  this->lifeSpan = 5.0;
46
47  this->emitter = new DotEmitter(100, 5, M_2_PI);
48  this->emitter->setParent(this);
49  this->emitter->setSpread(M_PI, M_PI);
50  this->emitter->setEmissionRate(300.0);
51  this->emitter->setEmissionVelocity(50.0);
52}
53
54
55/**
56 *  standard deconstructor
57*/
58HBolt::~HBolt ()
59{
60  // delete this->emitter;
61
62  /* this is normaly done by World.cc by deleting the ParticleEngine */
63  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
64  {
65    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
66    //  delete HBolt::explosionParticles;
67    PRINTF(1)("Deleting HBolt Particles\n");
68    HBolt::explosionParticles = NULL;
69  }
70
71}
72
73SpriteParticles* HBolt::explosionParticles = NULL;
74
75void HBolt::activate()
76{
77  if (unlikely(HBolt::explosionParticles == NULL))
78  {
79    HBolt::explosionParticles = new SpriteParticles(1000);
80    HBolt::explosionParticles->setName("HBoltExplosionParticles");
81    HBolt::explosionParticles->setLifeSpan(.5, .3);
82    HBolt::explosionParticles->setRadius(0.0, 10.0);
83    HBolt::explosionParticles->setRadius(.5, 6.0);
84    HBolt::explosionParticles->setRadius(1.0, 3.0);
85    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
86    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
87    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
88  }
89
90  this->setDamage(20);
91  this->setHealth(0);
92}
93
94
95void HBolt::deactivate()
96{
97  assert (HBolt::explosionParticles != NULL);
98  HBolt::explosionParticles->removeEmitter(this->emitter);
99  this->lifeCycle = 0.0;
100
101  this->toList(OM_NULL);
102  this->removeNode();
103  HBolt::fastFactory->kill(this);
104}
105
106
107void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
108{
109  if (this->hitEntity != entity && entity->isA(CL_NPC))
110    this->destroy( entity );
111  this->hitEntity = entity;
112}
113
114/**
115 *  signal tick, time dependent things will be handled here
116 * @param dt time since last tick
117*/
118void HBolt::tick (float dt)
119{
120  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
121  Vector v = this->velocity * dt;
122  this->shiftCoor(v);
123
124  if (this->tickLifeCycle(dt))
125    this->deactivate();
126
127
128}
129
130/**
131 *  the function gets called, when the projectile is destroyed
132*/
133void HBolt::destroy (WorldEntity* killer)
134{
135  Projectile::destroy( killer );
136  PRINTF(5)("DESTROY HBolt\n");
137  this->lifeCycle = .95; //!< @todo calculate this usefully.
138
139  this->emitter->setSystem(HBolt::explosionParticles);
140}
141
142
143void HBolt::draw () const
144{
145  glPushAttrib(GL_ENABLE_BIT);
146  glDisable(GL_LIGHTING);
147
148  //glPushMatrix();
149  //glRotatef(30, 0.0f, 1.0f, 0.0f);
150
151  WorldEntity::draw();
152/*  glMatrixMode(GL_MODELVIEW);
153  glPushMatrix();
154
155  float matrix[4][4];
156  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
157  this->getAbsDir().matrix (matrix);
158  glMultMatrixf((float*)matrix);
159  glScalef(2.0, 2.0, 2.0);
160  this->getModel()->draw();
161  glPopMatrix();*/
162
163/*
164
165  float matrix[4][4];
166  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
167  this->getAbsDir().matrix (matrix);
168  glMultMatrixf((float*)matrix);
169  glRotatef(30, 0.0, 1.0, 0.0);
170  //glMultMatrixf((float*)matrix);
171  this->getModel()->draw();*/
172  //glPopMatrix();
173  glPopAttrib();
174}
175
Note: See TracBrowser for help on using the repository browser.