Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/old.we/src/world_entities/weapons/bomb.cc @ 5796

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

orxonox/trunk: moved old world_entites branche out of the way

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 "list.h"
20#include "model.h"
21#include "vector.h"
22#include "fast_factory.h"
23
24#include "object_manager.h"
25
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->remove();
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
65}
66
67
68/**
69 * initializes the Bomb
70 * @todo change this to what you wish
71 */
72void Bomb::init()
73{
74  this->setClassID(CL_BOMB, "Bomb");
75
76  /**
77   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
78   */
79
80}
81
82
83/**
84 * loads a Bomb from a XML-element
85 * @param root the XML-element to load from
86 * @todo make the class Loadable
87 */
88void Bomb::loadParams(const TiXmlElement* root)
89{
90  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
91  static_cast<WorldEntity*>(this)->loadParams(root);
92
93
94  /**
95   * @todo: make the class Loadable
96   */
97}
98
99
100/**
101 * advances the Bomb about time seconds
102 * @param time the Time to step
103 */
104void Bomb::tick(float time)
105{
106  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
107  Vector v = this->velocity * (time);
108  this->shiftCoor(v);
109  /////////////////////////////////////////////////////////////////////////////////////////
110  // TESTING THE OBJECT MANAGER  //////////////////////////////////////////////////////////
111  /////////////////////////////////////////////////////////////////////////////////////////
112
113  std::list<WorldEntity*>* objList = ObjectManager::distanceFromObject(*this, 100, CL_NPC);
114  std::list<WorldEntity*>::const_iterator detonator;
115  for (detonator = objList->begin(); detonator != objList->end(); ++detonator)
116  {
117//    printf("%d\n", strlen((*detonator)->getName()));
118    (*detonator)->collidesWith(this, Vector(0,0,0));
119
120  }
121  /////////////////////////////////////////////////////////////////////////////////////////
122
123  this->lifeCycle += time/this->lifeSpan;
124  if( this->lifeCycle >= 1.0)
125    {
126      PRINTF(5)("FINALIZE==========================\n");
127      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
128      PRINTF(5)("FINALIZE===========================\n");
129
130      this->deactivate();
131    }
132}
133
134/**
135 * draws this worldEntity
136 */
137void Bomb::draw () const
138{
139  glMatrixMode(GL_MODELVIEW);
140  glPushMatrix();
141  float matrix[4][4];
142
143  /* translate */
144  glTranslatef (this->getAbsCoor ().x,
145                this->getAbsCoor ().y,
146                this->getAbsCoor ().z);
147  /* rotate */
148  this->getAbsDir().matrix(matrix);
149  glMultMatrixf((float*)matrix);
150
151  if (model)
152    model->draw();
153  glPopMatrix();
154}
155
156
157/**
158 *
159 *
160 */
161void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
162{
163        this->detonate();
164}
165
166void Bomb::activate()
167{
168  State::getWorldEntityList()->add(this);
169
170}
171
172void Bomb::deactivate()
173{
174  State::getWorldEntityList()->remove(this);
175  Bomb::fastFactory->kill(this);
176}
177
178void Bomb::detonate()
179{
180  tIterator<WorldEntity>* it = State::getWorldEntityList()->getIterator();
181  WorldEntity* lm = it->firstElement();
182
183  while(lm != NULL)
184  {
185
186    lm = it->nextElement();
187  }
188}
Note: See TracBrowser for help on using the repository browser.