[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 | |
---|
[8362] | 25 | #include "debug.h" |
---|
[5590] | 26 | |
---|
[5603] | 27 | CREATE_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 | */ |
---|
| 33 | Bomb::Bomb(const TiXmlElement* root) |
---|
| 34 | { |
---|
| 35 | this->init(); |
---|
| 36 | if (root != NULL) |
---|
| 37 | this->loadParams(root); |
---|
[5744] | 38 | |
---|
| 39 | this->loadModel("models/projectiles/RadioActiveBomb.obj", 1.0); |
---|
| 40 | |
---|
[6431] | 41 | this->setMinEnergy(1); |
---|
[6700] | 42 | this->setHealthMax(10); |
---|
[6431] | 43 | |
---|
[5744] | 44 | this->lifeSpan = 15; |
---|
| 45 | |
---|
[6825] | 46 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[5744] | 47 | this->emitter->setParent(this); |
---|
| 48 | this->emitter->setSpread(M_PI, M_PI); |
---|
[5590] | 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * standard deconstructor |
---|
| 54 | */ |
---|
| 55 | Bomb::~Bomb () |
---|
| 56 | { |
---|
[5828] | 57 | delete this->detonationSphere; |
---|
| 58 | delete this->detonationMaterial; |
---|
[5590] | 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * initializes the Bomb |
---|
| 65 | * @todo change this to what you wish |
---|
| 66 | */ |
---|
| 67 | void Bomb::init() |
---|
| 68 | { |
---|
[5603] | 69 | this->setClassID(CL_BOMB, "Bomb"); |
---|
[5590] | 70 | |
---|
[5828] | 71 | |
---|
| 72 | this->detonationSphere = new PrimitiveModel(PRIM_SPHERE); |
---|
| 73 | this->detonationMaterial = new Material(); |
---|
| 74 | this->detonationMaterial->setDiffuse(1, 0, 0); |
---|
[7084] | 75 | |
---|
| 76 | this->loadExplosionSound("sound/explosions/explosion_7_far.wav"); |
---|
[5828] | 77 | // this->detonationMaterial->setTransparency(.1); |
---|
[5590] | 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 | */ |
---|
| 90 | void 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. |
---|
[6512] | 93 | Projectile::loadParams(root); |
---|
[5590] | 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 | */ |
---|
[5603] | 106 | void Bomb::tick(float time) |
---|
[5590] | 107 | { |
---|
[5744] | 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 | } |
---|
[5828] | 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 | } |
---|
[5590] | 124 | } |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * draws this worldEntity |
---|
| 128 | */ |
---|
| 129 | void 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 | |
---|
[5828] | 143 | if (this->lifeCycle < .9) |
---|
| 144 | { |
---|
[5994] | 145 | if (this->getModel() != NULL) |
---|
| 146 | this->getModel()->draw(); |
---|
[5828] | 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 | } |
---|
[5590] | 156 | glPopMatrix(); |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | /** |
---|
| 161 | * |
---|
| 162 | * |
---|
| 163 | */ |
---|
| 164 | void Bomb::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 165 | { |
---|
[5828] | 166 | if (this->lifeCycle < .9f && entity->isA(CL_NPC)) |
---|
| 167 | this->lifeCycle = 0.9f; |
---|
[5590] | 168 | } |
---|
[5603] | 169 | |
---|
| 170 | void Bomb::activate() |
---|
| 171 | { |
---|
| 172 | |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | void Bomb::deactivate() |
---|
| 176 | { |
---|
[6142] | 177 | this->toList(OM_DEAD); |
---|
[5828] | 178 | this->lifeCycle = 0.0f; |
---|
[5744] | 179 | Bomb::fastFactory->kill(this); |
---|
| 180 | } |
---|
[5603] | 181 | |
---|
[5826] | 182 | void Bomb::detonate(float size) |
---|
[5744] | 183 | { |
---|
[7368] | 184 | ObjectManager::EntityList detonationList; |
---|
| 185 | ObjectManager::distanceFromObject(detonationList, *this, size, CL_NPC); |
---|
| 186 | while( !detonationList.empty() ) |
---|
[5826] | 187 | { |
---|
[7368] | 188 | detonationList.front()->collidesWith(this, Vector(0,0,0)); |
---|
| 189 | detonationList.pop_front(); |
---|
[5826] | 190 | } |
---|
[5603] | 191 | } |
---|