[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 <cassert> |
---|
| 25 | #include "debug.h" |
---|
| 26 | |
---|
| 27 | #include "effects/wobblegrid.h" |
---|
| 28 | |
---|
| 29 | |
---|
[10366] | 30 | |
---|
[10179] | 31 | ObjectListDefinition(AcidSplash); |
---|
| 32 | CREATE_FAST_FACTORY_STATIC(AcidSplash); |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * standard constructor |
---|
| 36 | */ |
---|
| 37 | AcidSplash::AcidSplash () : Projectile() |
---|
| 38 | { |
---|
| 39 | this->registerObject(this, AcidSplash::_objectList); |
---|
| 40 | |
---|
[10701] | 41 | // moved to baseObject |
---|
| 42 | // srand(time(0)); //initialize Random Nomber Generator |
---|
[10298] | 43 | |
---|
[10179] | 44 | this->setMinEnergy(1); |
---|
| 45 | this->setHealthMax(0); |
---|
| 46 | this->lifeSpan = 3.0; |
---|
| 47 | this->angle = 0; |
---|
| 48 | |
---|
| 49 | this->grid = new Wobblegrid( 5); |
---|
| 50 | this->grid->setParent( this); |
---|
[10511] | 51 | this->grid->setVisibility(false); |
---|
[10179] | 52 | |
---|
[10333] | 53 | |
---|
[10345] | 54 | int rnd = int(rand() % 3); |
---|
[10333] | 55 | |
---|
| 56 | switch (rnd){ |
---|
| 57 | case 0: |
---|
[10420] | 58 | this->grid->setTexture( "textures/acid2.png"); |
---|
[10333] | 59 | break; |
---|
| 60 | case 1: |
---|
[10420] | 61 | this->grid->setTexture( "textures/acid3.png"); |
---|
[10333] | 62 | break; |
---|
| 63 | case 2: |
---|
[10420] | 64 | this->grid->setTexture( "textures/blub.png"); |
---|
[10333] | 65 | break; |
---|
| 66 | default: |
---|
[10420] | 67 | this->grid->setTexture( "textures/acid2.png"); |
---|
[10333] | 68 | } |
---|
[10298] | 69 | |
---|
[10345] | 70 | this->grid->toList(OM_ENVIRON); |
---|
[10179] | 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * standard deconstructor |
---|
| 76 | * |
---|
| 77 | */ |
---|
| 78 | AcidSplash::~AcidSplash () |
---|
| 79 | { |
---|
[10328] | 80 | this->grid->toList(OM_DEAD); |
---|
[10179] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | void AcidSplash::activate() |
---|
| 85 | { |
---|
[10345] | 86 | this->origList = this->getOMListNumber(); |
---|
| 87 | this->toList(OM_ENVIRON); |
---|
| 88 | // this->unhide(); |
---|
[10511] | 89 | this->grid->setVisibility(true); |
---|
[10179] | 90 | |
---|
| 91 | this->setPhysDamage(10); |
---|
| 92 | this->setElecDamage(0); |
---|
| 93 | this->setHealth(0); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | void AcidSplash::deactivate() |
---|
| 98 | { |
---|
| 99 | this->lifeCycle = 0.0; |
---|
| 100 | |
---|
[10345] | 101 | // this->hide(); |
---|
[10511] | 102 | this->grid->setVisibility(false); |
---|
[10345] | 103 | this->lifeCycle = 0.0; |
---|
| 104 | this->toList(OM_NULL); |
---|
| 105 | //this->toList(OM_DEAD); |
---|
[10698] | 106 | // this->removeNode(); |
---|
| 107 | |
---|
[10179] | 108 | AcidSplash::fastFactory->kill(this); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * signal tick, time dependent things will be handled here |
---|
| 114 | * @param dt time since last tick |
---|
| 115 | */ |
---|
| 116 | void AcidSplash::tick (float dt) |
---|
| 117 | { |
---|
| 118 | Vector v = this->velocity * dt; |
---|
| 119 | this->shiftCoor(v); |
---|
| 120 | |
---|
| 121 | if (this->tickLifeCycle(dt)) |
---|
| 122 | this->deactivate(); |
---|
| 123 | |
---|
| 124 | this->angle += this->rotationSpeed * dt; |
---|
| 125 | |
---|
| 126 | this->grid->tick(dt); |
---|
| 127 | |
---|
[10328] | 128 | for( ObjectList<Playable>::const_iterator eIterator = Playable::objectList().begin(); eIterator !=Playable::objectList().end(); eIterator++) |
---|
| 129 | { |
---|
[10345] | 130 | if( ((*eIterator)->getOMListNumber() != (this->origList -1)) && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 8) |
---|
[10328] | 131 | { |
---|
| 132 | (*eIterator)->hit (this->getDamage(),this); |
---|
| 133 | this->deactivate(); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
[10179] | 137 | } |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | * the function gets called, when the projectile is destroyed |
---|
| 141 | */ |
---|
| 142 | void AcidSplash::destroy (WorldEntity* killer) |
---|
| 143 | { |
---|
| 144 | this->deactivate(); |
---|
| 145 | Projectile::destroy( killer ); |
---|
| 146 | PRINTF(5)("DESTROY AcidSplash\n"); |
---|
| 147 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | void AcidSplash::draw () const |
---|
| 152 | { |
---|
| 153 | this->grid->draw(); |
---|
| 154 | } |
---|