Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/world_entities/projectiles/bomb.cc @ 9370

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

orxonox/trunk: new style for resources (prework/movement)

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 "model.h"
20#include "primitive_model.h"
21
22#include "dot_emitter.h"
23#include "particle_system.h"
24
25using namespace std;
26
27CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
28
29/**
30 * constructs and loads a Bomb from a XML-element
31 * @param root the XML-element to load from
32 */
33Bomb::Bomb(const TiXmlElement* root)
34{
35  this->init();
36  if (root != NULL)
37    this->loadParams(root);
38
39  float modelSize = 1.0;
40  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
41
42  this->setMinEnergy(1);
43  this->setHealthMax(10);
44
45  this->lifeSpan = 15;
46
47  this->emitter = new DotEmitter(100, 5, M_2_PI);
48  this->emitter->setParent(this);
49  this->emitter->setSpread(M_PI, M_PI);
50}
51
52
53/**
54 * standard deconstructor
55 */
56Bomb::~Bomb ()
57{
58  delete this->detonationSphere;
59  delete this->detonationMaterial;
60
61}
62
63
64/**
65 * initializes the Bomb
66 * @todo change this to what you wish
67 */
68void Bomb::init()
69{
70  this->setClassID(CL_BOMB, "Bomb");
71
72
73  this->detonationSphere = new PrimitiveModel(PRIM_SPHERE);
74  this->detonationMaterial = new Material();
75  this->detonationMaterial->setDiffuse(1, 0, 0);
76
77  this->loadExplosionSound("sound/explosions/explosion_7_far.wav");
78  //   this->detonationMaterial->setTransparency(.1);
79  /**
80   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
81   */
82
83}
84
85
86/**
87 * loads a Bomb from a XML-element
88 * @param root the XML-element to load from
89 * @todo make the class Loadable
90 */
91void Bomb::loadParams(const TiXmlElement* root)
92{
93  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
94  Projectile::loadParams(root);
95
96
97  /**
98   * @todo: make the class Loadable
99   */
100}
101
102
103/**
104 * advances the Bomb about time seconds
105 * @param time the Time to step
106 */
107void Bomb::tick(float time)
108{
109  this->lifeCycle += time/this->lifeSpan;
110  if( this->lifeCycle >= 1.0)
111    {
112      PRINTF(5)("FINALIZE==========================\n");
113      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
114      PRINTF(5)("FINALIZE===========================\n");
115
116      this->deactivate();
117    }
118  else if (this->lifeCycle > 0.9f)
119    this->detonate ((this->lifeCycle-.89) *1000.0);
120  else
121  {
122    Vector v = this->velocity * (time);
123    this->shiftCoor(v);
124  }
125}
126
127/**
128 * draws this worldEntity
129 */
130void Bomb::draw () const
131{
132  glMatrixMode(GL_MODELVIEW);
133  glPushMatrix();
134  float matrix[4][4];
135
136  /* translate */
137  glTranslatef (this->getAbsCoor ().x,
138                this->getAbsCoor ().y,
139                this->getAbsCoor ().z);
140  /* rotate */
141  this->getAbsDir().matrix(matrix);
142  glMultMatrixf((float*)matrix);
143
144  if (this->lifeCycle < .9)
145  {
146    if (this->getModel() != NULL)
147      this->getModel()->draw();
148  }
149  else
150  {
151    glScalef((this->lifeCycle-.89) *1000.0,
152              (this->lifeCycle-.89) *1000.0,
153              (this->lifeCycle-.89) *1000.0);
154    this->detonationMaterial->select();
155    this->detonationSphere->draw();
156  }
157  glPopMatrix();
158}
159
160
161/**
162 *
163 *
164 */
165void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
166{
167  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
168    this->lifeCycle = 0.9f;
169}
170
171void Bomb::activate()
172{
173
174}
175
176void Bomb::deactivate()
177{
178  this->toList(OM_DEAD);
179  this->lifeCycle = 0.0f;
180  Bomb::fastFactory->kill(this);
181}
182
183void Bomb::detonate(float size)
184{
185  std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC);
186  if (detonationList != NULL)
187  {
188    while( !detonationList->empty() )
189    {
190      detonationList->front()->collidesWith(this, Vector(0,0,0));
191      detonationList->pop_front();
192    }
193    delete detonationList;
194  }
195}
Note: See TracBrowser for help on using the repository browser.