Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/bomb.cc @ 6746

Last change on this file since 6746 was 6700, checked in by bensch, 19 years ago

trunk: Energy→Health

File size: 4.0 KB
RevLine 
[5590]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"
[5603]17#include "glincl.h"
[5744]18#include "state.h"
[5603]19#include "model.h"
[5828]20#include "primitive_model.h"
21
[5603]22#include "fast_factory.h"
[5590]23
[6222]24
[5826]25#include "object_manager.h"
[5744]26
27#include "particle_emitter.h"
28#include "particle_system.h"
29
[5590]30using namespace std;
31
[5603]32CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
[5590]33
34/**
35 * constructs and loads a Bomb from a XML-element
36 * @param root the XML-element to load from
37 */
38Bomb::Bomb(const TiXmlElement* root)
39{
40  this->init();
41  if (root != NULL)
42    this->loadParams(root);
[5744]43
44  float modelSize = 1.0;
45  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
46
[6431]47  this->setMinEnergy(1);
[6700]48  this->setHealthMax(10);
[6431]49
[5744]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);
[5590]55}
56
57
58/**
59 * standard deconstructor
60 */
61Bomb::~Bomb ()
62{
[5828]63  delete this->detonationSphere;
64  delete this->detonationMaterial;
[5590]65
66}
67
68
69/**
70 * initializes the Bomb
71 * @todo change this to what you wish
72 */
73void Bomb::init()
74{
[5603]75  this->setClassID(CL_BOMB, "Bomb");
[5590]76
[5828]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);
[5590]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.
[6512]97  Projectile::loadParams(root);
[5590]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 */
[5603]110void Bomb::tick(float time)
[5590]111{
[5744]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    }
[5828]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  }
[5590]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
[5828]147  if (this->lifeCycle < .9)
148  {
[5994]149    if (this->getModel() != NULL)
150      this->getModel()->draw();
[5828]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  }
[5590]160  glPopMatrix();
161}
162
163
164/**
165 *
166 *
167 */
168void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
169{
[5828]170  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
171    this->lifeCycle = 0.9f;
[5590]172}
[5603]173
174void Bomb::activate()
175{
176
177}
178
179void Bomb::deactivate()
180{
[6142]181  this->toList(OM_DEAD);
[5828]182  this->lifeCycle = 0.0f;
[5744]183  Bomb::fastFactory->kill(this);
184}
[5603]185
[5826]186void Bomb::detonate(float size)
[5744]187{
[5826]188  std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC);
189  if (detonationList != NULL)
[5744]190  {
[5826]191    while( !detonationList->empty() )
192    {
[5828]193      detonationList->front()->collidesWith(this, Vector(0,0,0));
[5826]194      detonationList->pop_front();
195    }
196    delete detonationList;
[5744]197  }
[5603]198}
Note: See TracBrowser for help on using the repository browser.