Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6494 was 6434, checked in by bensch, 19 years ago

orxonox/trunk: moved the projectiles to Projectiles

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_engine.h"
28#include "particle_emitter.h"
29#include "particle_system.h"
30
[5590]31using namespace std;
32
[5603]33CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
[5590]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);
[5744]44
45  float modelSize = 1.0;
46  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
47
[6431]48  this->setMinEnergy(1);
49  this->setMaxEnergy(10);
50
[5744]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);
[5590]56}
57
58
59/**
60 * standard deconstructor
61 */
62Bomb::~Bomb ()
63{
[5828]64  delete this->detonationSphere;
65  delete this->detonationMaterial;
[5590]66
67}
68
69
70/**
71 * initializes the Bomb
72 * @todo change this to what you wish
73 */
74void Bomb::init()
75{
[5603]76  this->setClassID(CL_BOMB, "Bomb");
[5590]77
[5828]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);
[5590]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.
[5603]98  static_cast<WorldEntity*>(this)->loadParams(root);
[5590]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 */
[5603]111void Bomb::tick(float time)
[5590]112{
[5744]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    }
[5828]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  }
[5590]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
[5828]148  if (this->lifeCycle < .9)
149  {
[5994]150    if (this->getModel() != NULL)
151      this->getModel()->draw();
[5828]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  }
[5590]161  glPopMatrix();
162}
163
164
165/**
166 *
167 *
168 */
169void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
170{
[5828]171  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
172    this->lifeCycle = 0.9f;
[5590]173}
[5603]174
175void Bomb::activate()
176{
177
178}
179
180void Bomb::deactivate()
181{
[6142]182  this->toList(OM_DEAD);
[5828]183  this->lifeCycle = 0.0f;
[5744]184  Bomb::fastFactory->kill(this);
185}
[5603]186
[5826]187void Bomb::detonate(float size)
[5744]188{
[5826]189  std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC);
190  if (detonationList != NULL)
[5744]191  {
[5826]192    while( !detonationList->empty() )
193    {
[5828]194      detonationList->front()->collidesWith(this, Vector(0,0,0));
[5826]195      detonationList->pop_front();
196    }
197    delete detonationList;
[5744]198  }
[5603]199}
Note: See TracBrowser for help on using the repository browser.