Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/preferences/src/world_entities/weapons/bomb.cc @ 6658

Last change on this file since 6658 was 6222, checked in by bensch, 19 years ago

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

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