Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/bomb.cc @ 10677

Last change on this file since 10677 was 10415, checked in by patrick, 18 years ago

changed the path names to reflect the new data repos

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