Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/guidedmissile/src/world_entities/weapons/bomb.cc @ 5855

Last change on this file since 5855 was 5750, checked in by bensch, 19 years ago

orxonox/trunk: merged the WorldEntities into the Trunk.
Merged with command:
svn merge branches/world_entities/ trunk/ -r5516:HEAD

conflics from world_entities changed in favor of branches/world_entity
all other conflict in favor of the trunk

File size: 3.3 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 "list.h"
20#include "model.h"
21#include "vector.h"
22#include "fast_factory.h"
23
24
25#include "particle_engine.h"
26#include "particle_emitter.h"
27#include "particle_system.h"
28
29using namespace std;
30
31CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
32
33/**
34 * constructs and loads a Bomb from a XML-element
35 * @param root the XML-element to load from
36 */
37Bomb::Bomb(const TiXmlElement* root)
38{
39  this->init();
40  if (root != NULL)
41    this->loadParams(root);
42
43  float modelSize = 1.0;
44  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
45
46  this->energyMin = 1;
47  this->energyMax = 1;
48  this->remove();
49  this->lifeSpan = 15;
50
51  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
52  this->emitter->setParent(this);
53  this->emitter->setSpread(M_PI, M_PI);
54}
55
56
57/**
58 * standard deconstructor
59 */
60Bomb::~Bomb ()
61{
62
63}
64
65
66/**
67 * initializes the Bomb
68 * @todo change this to what you wish
69 */
70void Bomb::init()
71{
72  this->setClassID(CL_BOMB, "Bomb");
73
74  /**
75   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
76   */
77
78}
79
80
81/**
82 * loads a Bomb from a XML-element
83 * @param root the XML-element to load from
84 * @todo make the class Loadable
85 */
86void Bomb::loadParams(const TiXmlElement* root)
87{
88  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
89  static_cast<WorldEntity*>(this)->loadParams(root);
90
91
92  /**
93   * @todo: make the class Loadable
94   */
95}
96
97
98/**
99 * advances the Bomb about time seconds
100 * @param time the Time to step
101 */
102void Bomb::tick(float time)
103{
104  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
105  Vector v = this->velocity * (time);
106  this->shiftCoor(v);
107
108  this->lifeCycle += time/this->lifeSpan;
109  if( this->lifeCycle >= 1.0)
110    {
111      PRINTF(5)("FINALIZE==========================\n");
112      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
113      PRINTF(5)("FINALIZE===========================\n");
114
115      this->deactivate();
116    }
117}
118
119/**
120 * draws this worldEntity
121 */
122void Bomb::draw () const
123{
124  glMatrixMode(GL_MODELVIEW);
125  glPushMatrix();
126  float matrix[4][4];
127
128  /* translate */
129  glTranslatef (this->getAbsCoor ().x,
130                this->getAbsCoor ().y,
131                this->getAbsCoor ().z);
132  /* rotate */
133  this->getAbsDir().matrix(matrix);
134  glMultMatrixf((float*)matrix);
135
136  if (model)
137    model->draw();
138  glPopMatrix();
139}
140
141
142/**
143 *
144 *
145 */
146void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
147{
148        this->detonate();
149}
150
151void Bomb::activate()
152{
153  State::getWorldEntityList()->add(this);
154
155}
156
157void Bomb::deactivate()
158{
159  State::getWorldEntityList()->remove(this);
160  Bomb::fastFactory->kill(this);
161}
162
163void Bomb::detonate()
164{
165  tIterator<WorldEntity>* it = State::getWorldEntityList()->getIterator();
166  WorldEntity* lm = it->firstElement();
167
168  while(lm != NULL)
169  {
170   
171    lm = it->nextElement();
172  }
173}
Note: See TracBrowser for help on using the repository browser.