| 1 | #include "Projectile.h" | 
|---|
| 2 | #include "../core/CoreIncludes.h" | 
|---|
| 3 | #include "Explosion.h" | 
|---|
| 4 | #include "Model.h" | 
|---|
| 5 |  | 
|---|
| 6 | namespace orxonox | 
|---|
| 7 | { | 
|---|
| 8 |     CreateFactory(Projectile); | 
|---|
| 9 |  | 
|---|
| 10 |     Projectile::Projectile(SpaceShip* owner) | 
|---|
| 11 |     { | 
|---|
| 12 |         RegisterObject(Projectile); | 
|---|
| 13 |  | 
|---|
| 14 |         this->owner_ = owner; | 
|---|
| 15 |  | 
|---|
| 16 |         SetConfigValue(lifetime_, 10.0); | 
|---|
| 17 |         SetConfigValue(speed_, 2000.0); | 
|---|
| 18 |  | 
|---|
| 19 |         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1); | 
|---|
| 20 |         this->attachObject(this->billboard_.getBillboardSet()); | 
|---|
| 21 |         this->scale(0.5); | 
|---|
| 22 |  | 
|---|
| 23 |         if (this->owner_) | 
|---|
| 24 |         { | 
|---|
| 25 |             this->setStatic(false); | 
|---|
| 26 |             this->setOrientation(this->owner_->getOrientation()); | 
|---|
| 27 |             this->setPosition(this->owner_->getPosition()); | 
|---|
| 28 |             this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); | 
|---|
| 29 |             this->setVelocity(Vector3(1, 0, 0) * this->speed_); | 
|---|
| 30 |         } | 
|---|
| 31 |  | 
|---|
| 32 |         this->destroyTimer_.setTimer(this->lifetime_, false, this, &Projectile::destroyObject); | 
|---|
| 33 |     } | 
|---|
| 34 |  | 
|---|
| 35 |     Projectile::~Projectile() | 
|---|
| 36 |     { | 
|---|
| 37 |     } | 
|---|
| 38 |  | 
|---|
| 39 |     void Projectile::tick(float dt) | 
|---|
| 40 |     { | 
|---|
| 41 |         WorldEntity::tick(dt); | 
|---|
| 42 |  | 
|---|
| 43 |         float radius; | 
|---|
| 44 |         for (Iterator<Model> it = ObjectList<Model>::start(); it; ++it) | 
|---|
| 45 |         { | 
|---|
| 46 |             if ((*it) != this->owner_) | 
|---|
| 47 |             { | 
|---|
| 48 |                 radius = it->getScale().x * 3.0; | 
|---|
| 49 |  | 
|---|
| 50 |                 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) | 
|---|
| 51 |                 { | 
|---|
| 52 |                     Explosion* eplosion = new Explosion(this); | 
|---|
| 53 |                     delete this; | 
|---|
| 54 |                     return; | 
|---|
| 55 |                 } | 
|---|
| 56 |             } | 
|---|
| 57 |         } | 
|---|
| 58 |     } | 
|---|
| 59 |  | 
|---|
| 60 |     void Projectile::destroyObject() | 
|---|
| 61 |     { | 
|---|
| 62 |         delete this; | 
|---|
| 63 |     } | 
|---|
| 64 | } | 
|---|