Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/script_engine/src/world_entities/projectiles/bomb.cc @ 8453

Last change on this file since 8453 was 8362, checked in by bensch, 18 years ago

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

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