Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some renamings, and GameWorldData now has lists for what EntityLists should be drawed/ticked/collided(not yet implemented).

File size: 3.9 KB
RevLine 
[5590]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"
[5603]17#include "glincl.h"
[5744]18#include "state.h"
[5603]19#include "model.h"
[5828]20#include "primitive_model.h"
21
[6822]22#include "dot_emitter.h"
[5744]23#include "particle_system.h"
24
[5590]25using namespace std;
26
[5603]27CREATE_FAST_FACTORY_STATIC(Bomb, CL_BOMB);
[5590]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);
[5744]38
39  float modelSize = 1.0;
40  this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0);
41
[6431]42  this->setMinEnergy(1);
[6700]43  this->setHealthMax(10);
[6431]44
[5744]45  this->lifeSpan = 15;
46
[6825]47  this->emitter = new DotEmitter(100, 5, M_2_PI);
[5744]48  this->emitter->setParent(this);
49  this->emitter->setSpread(M_PI, M_PI);
[5590]50}
51
52
53/**
54 * standard deconstructor
55 */
56Bomb::~Bomb ()
57{
[5828]58  delete this->detonationSphere;
59  delete this->detonationMaterial;
[5590]60
61}
62
63
64/**
65 * initializes the Bomb
66 * @todo change this to what you wish
67 */
68void Bomb::init()
69{
[5603]70  this->setClassID(CL_BOMB, "Bomb");
[5590]71
[5828]72
73  this->detonationSphere = new PrimitiveModel(PRIM_SPHERE);
74  this->detonationMaterial = new Material();
75  this->detonationMaterial->setDiffuse(1, 0, 0);
[7084]76
77  this->loadExplosionSound("sound/explosions/explosion_7_far.wav");
[5828]78  //   this->detonationMaterial->setTransparency(.1);
[5590]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.
[6512]94  Projectile::loadParams(root);
[5590]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 */
[5603]107void Bomb::tick(float time)
[5590]108{
[5744]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    }
[5828]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  }
[5590]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
[5828]144  if (this->lifeCycle < .9)
145  {
[5994]146    if (this->getModel() != NULL)
147      this->getModel()->draw();
[5828]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  }
[5590]157  glPopMatrix();
158}
159
160
161/**
162 *
163 *
164 */
165void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
166{
[5828]167  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
168    this->lifeCycle = 0.9f;
[5590]169}
[5603]170
171void Bomb::activate()
172{
173
174}
175
176void Bomb::deactivate()
177{
[6142]178  this->toList(OM_DEAD);
[5828]179  this->lifeCycle = 0.0f;
[5744]180  Bomb::fastFactory->kill(this);
181}
[5603]182
[5826]183void Bomb::detonate(float size)
[5744]184{
[7368]185  ObjectManager::EntityList detonationList;
186  ObjectManager::distanceFromObject(detonationList, *this, size, CL_NPC);
187    while( !detonationList.empty() )
[5826]188    {
[7368]189      detonationList.front()->collidesWith(this, Vector(0,0,0));
190      detonationList.pop_front();
[5826]191    }
[5603]192}
Note: See TracBrowser for help on using the repository browser.