[10179] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004-2006 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: Marc Schaerrer |
---|
| 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 19 | |
---|
| 20 | #include "acid_splash.h" |
---|
| 21 | |
---|
| 22 | #include "state.h" |
---|
| 23 | |
---|
| 24 | //#include "space_ships/space_ship.h" |
---|
| 25 | |
---|
| 26 | #include <cassert> |
---|
| 27 | #include "debug.h" |
---|
| 28 | |
---|
| 29 | //#include "static_model.h" |
---|
| 30 | |
---|
| 31 | #include "effects/wobblegrid.h" |
---|
| 32 | |
---|
| 33 | |
---|
[10366] | 34 | |
---|
[10179] | 35 | ObjectListDefinition(AcidSplash); |
---|
| 36 | CREATE_FAST_FACTORY_STATIC(AcidSplash); |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * standard constructor |
---|
| 40 | */ |
---|
| 41 | AcidSplash::AcidSplash () : Projectile() |
---|
| 42 | { |
---|
| 43 | this->registerObject(this, AcidSplash::_objectList); |
---|
| 44 | |
---|
[10298] | 45 | srand(time(0)); //initialize Random Nomber Generator |
---|
| 46 | |
---|
[10179] | 47 | //this->loadModel("models/projectiles/laser.obj"); |
---|
| 48 | |
---|
| 49 | this->setMinEnergy(1); |
---|
| 50 | this->setHealthMax(0); |
---|
| 51 | this->lifeSpan = 3.0; |
---|
| 52 | this->angle = 0; |
---|
| 53 | |
---|
| 54 | this->grid = new Wobblegrid( 5); |
---|
| 55 | this->grid->setParent( this); |
---|
[10511] | 56 | this->grid->setVisibility(false); |
---|
[10179] | 57 | |
---|
[10333] | 58 | |
---|
[10345] | 59 | int rnd = int(rand() % 3); |
---|
[10333] | 60 | |
---|
| 61 | switch (rnd){ |
---|
| 62 | case 0: |
---|
[10420] | 63 | this->grid->setTexture( "textures/acid2.png"); |
---|
[10333] | 64 | break; |
---|
| 65 | case 1: |
---|
[10420] | 66 | this->grid->setTexture( "textures/acid3.png"); |
---|
[10333] | 67 | break; |
---|
| 68 | case 2: |
---|
[10420] | 69 | this->grid->setTexture( "textures/blub.png"); |
---|
[10333] | 70 | break; |
---|
| 71 | default: |
---|
[10420] | 72 | this->grid->setTexture( "textures/acid2.png"); |
---|
[10333] | 73 | } |
---|
| 74 | // if (rand()/2 == 0) //!<Randomized Textrures |
---|
[10420] | 75 | // this->grid->setTexture( "textures/acid3.png"); |
---|
[10298] | 76 | // else |
---|
[10420] | 77 | // this->grid->setTexture( "textures/blub.png"); |
---|
[10298] | 78 | |
---|
[10345] | 79 | this->grid->toList(OM_ENVIRON); |
---|
[10179] | 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * standard deconstructor |
---|
| 85 | * |
---|
| 86 | */ |
---|
| 87 | AcidSplash::~AcidSplash () |
---|
| 88 | { |
---|
| 89 | // delete this->emitter; |
---|
| 90 | //delete this->grid; |
---|
[10328] | 91 | this->grid->toList(OM_DEAD); |
---|
| 92 | |
---|
[10179] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | void AcidSplash::activate() |
---|
| 97 | { |
---|
[10345] | 98 | this->origList = this->getOMListNumber(); |
---|
| 99 | this->toList(OM_ENVIRON); |
---|
| 100 | // this->unhide(); |
---|
[10511] | 101 | this->grid->setVisibility(true); |
---|
[10179] | 102 | |
---|
| 103 | this->setPhysDamage(10); |
---|
| 104 | this->setElecDamage(0); |
---|
| 105 | this->setHealth(0); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | void AcidSplash::deactivate() |
---|
| 110 | { |
---|
| 111 | this->lifeCycle = 0.0; |
---|
| 112 | |
---|
[10345] | 113 | // this->hide(); |
---|
[10511] | 114 | this->grid->setVisibility(false); |
---|
[10345] | 115 | this->lifeCycle = 0.0; |
---|
| 116 | this->toList(OM_NULL); |
---|
| 117 | //this->toList(OM_DEAD); |
---|
[10698] | 118 | // this->removeNode(); |
---|
| 119 | |
---|
[10179] | 120 | AcidSplash::fastFactory->kill(this); |
---|
| 121 | } |
---|
| 122 | |
---|
[10328] | 123 | /* |
---|
[10179] | 124 | void AcidSplash::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 125 | { |
---|
| 126 | |
---|
| 127 | if (this->hitEntity != entity) |
---|
| 128 | this->destroy( entity ); |
---|
| 129 | this->hitEntity = entity; |
---|
| 130 | //dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage()); |
---|
| 131 | //this->destroy(this); |
---|
| 132 | this->deactivate(); |
---|
| 133 | |
---|
[10333] | 134 | // return; |
---|
[10179] | 135 | |
---|
| 136 | //dynamic_cast<SpaceShip*>(entity)->damage( this->getPhysDamage(), this->getElecDamage()); |
---|
| 137 | //entity->destroy(this); |
---|
| 138 | //this->deactivate(); |
---|
| 139 | } |
---|
[10328] | 140 | */ |
---|
[10179] | 141 | /** |
---|
| 142 | * signal tick, time dependent things will be handled here |
---|
| 143 | * @param dt time since last tick |
---|
| 144 | */ |
---|
| 145 | void AcidSplash::tick (float dt) |
---|
| 146 | { |
---|
| 147 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 148 | Vector v = this->velocity * dt; |
---|
| 149 | this->shiftCoor(v); |
---|
| 150 | |
---|
| 151 | if (this->tickLifeCycle(dt)) |
---|
| 152 | this->deactivate(); |
---|
| 153 | |
---|
| 154 | this->angle += this->rotationSpeed * dt; |
---|
| 155 | |
---|
| 156 | this->grid->tick(dt); |
---|
| 157 | |
---|
[10328] | 158 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
| 159 | { |
---|
[10345] | 160 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
[10328] | 161 | { |
---|
| 162 | (*eIterator)->hit (this->getDamage(),this); |
---|
| 163 | this->deactivate(); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
[10179] | 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | * the function gets called, when the projectile is destroyed |
---|
| 171 | */ |
---|
| 172 | void AcidSplash::destroy (WorldEntity* killer) |
---|
| 173 | { |
---|
| 174 | this->deactivate(); |
---|
| 175 | Projectile::destroy( killer ); |
---|
| 176 | PRINTF(5)("DESTROY AcidSplash\n"); |
---|
| 177 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | void AcidSplash::draw () const |
---|
| 182 | { |
---|
| 183 | this->grid->draw(); |
---|
| 184 | } |
---|