Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/bomb.cc @ 5776

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

orxonox/trunk: sync

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