Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/projectiles/bomb.cc @ 6556

Last change on this file since 6556 was 6512, checked in by bensch, 19 years ago

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

File size: 4.0 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: Stefan Lienhard
13   co-programmer: ...
14*/
15
16#include "bomb.h"
17#include "glincl.h"
18#include "state.h"
19#include "model.h"
20#include "primitive_model.h"
21
22#include "fast_factory.h"
23
24
25#include "object_manager.h"
26
27#include "particle_engine.h"
28#include "particle_emitter.h"
29#include "particle_system.h"
30
31using namespace std;
32
33CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
34
35/**
36 * constructs and loads a Bomb from a XML-element
37 * @param root the XML-element to load from
38 */
39Bomb::Bomb(const TiXmlElement* root)
40{
41  this->init();
42  if (root != NULL)
43    this->loadParams(root);
44
45  float modelSize = 1.0;
46  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
47
48  this->setMinEnergy(1);
49  this->setMaxEnergy(10);
50
51  this->lifeSpan = 15;
52
53  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
54  this->emitter->setParent(this);
55  this->emitter->setSpread(M_PI, M_PI);
56}
57
58
59/**
60 * standard deconstructor
61 */
62Bomb::~Bomb ()
63{
64  delete this->detonationSphere;
65  delete this->detonationMaterial;
66
67}
68
69
70/**
71 * initializes the Bomb
72 * @todo change this to what you wish
73 */
74void Bomb::init()
75{
76  this->setClassID(CL_BOMB, "Bomb");
77
78
79  this->detonationSphere = new PrimitiveModel(PRIM_SPHERE);
80  this->detonationMaterial = new Material();
81  this->detonationMaterial->setDiffuse(1, 0, 0);
82  //   this->detonationMaterial->setTransparency(.1);
83  /**
84   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
85   */
86
87}
88
89
90/**
91 * loads a Bomb from a XML-element
92 * @param root the XML-element to load from
93 * @todo make the class Loadable
94 */
95void Bomb::loadParams(const TiXmlElement* root)
96{
97  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
98  Projectile::loadParams(root);
99
100
101  /**
102   * @todo: make the class Loadable
103   */
104}
105
106
107/**
108 * advances the Bomb about time seconds
109 * @param time the Time to step
110 */
111void Bomb::tick(float time)
112{
113  this->lifeCycle += time/this->lifeSpan;
114  if( this->lifeCycle >= 1.0)
115    {
116      PRINTF(5)("FINALIZE==========================\n");
117      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
118      PRINTF(5)("FINALIZE===========================\n");
119
120      this->deactivate();
121    }
122  else if (this->lifeCycle > 0.9f)
123    this->detonate ((this->lifeCycle-.89) *1000.0);
124  else
125  {
126    Vector v = this->velocity * (time);
127    this->shiftCoor(v);
128  }
129}
130
131/**
132 * draws this worldEntity
133 */
134void Bomb::draw () const
135{
136  glMatrixMode(GL_MODELVIEW);
137  glPushMatrix();
138  float matrix[4][4];
139
140  /* translate */
141  glTranslatef (this->getAbsCoor ().x,
142                this->getAbsCoor ().y,
143                this->getAbsCoor ().z);
144  /* rotate */
145  this->getAbsDir().matrix(matrix);
146  glMultMatrixf((float*)matrix);
147
148  if (this->lifeCycle < .9)
149  {
150    if (this->getModel() != NULL)
151      this->getModel()->draw();
152  }
153  else
154  {
155    glScalef((this->lifeCycle-.89) *1000.0,
156              (this->lifeCycle-.89) *1000.0,
157              (this->lifeCycle-.89) *1000.0);
158    this->detonationMaterial->select();
159    this->detonationSphere->draw();
160  }
161  glPopMatrix();
162}
163
164
165/**
166 *
167 *
168 */
169void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
170{
171  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
172    this->lifeCycle = 0.9f;
173}
174
175void Bomb::activate()
176{
177
178}
179
180void Bomb::deactivate()
181{
182  this->toList(OM_DEAD);
183  this->lifeCycle = 0.0f;
184  Bomb::fastFactory->kill(this);
185}
186
187void Bomb::detonate(float size)
188{
189  std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC);
190  if (detonationList != NULL)
191  {
192    while( !detonationList->empty() )
193    {
194      detonationList->front()->collidesWith(this, Vector(0,0,0));
195      detonationList->pop_front();
196    }
197    delete detonationList;
198  }
199}
Note: See TracBrowser for help on using the repository browser.