[10336] | 1 | /* |
---|
| 2 | * GravityBomb.cc |
---|
| 3 | * |
---|
| 4 | * Created on: Mar 26, 2015 |
---|
| 5 | * Author: meggiman |
---|
| 6 | */ |
---|
| 7 | #include "GravityBomb.h" |
---|
[10369] | 8 | #include "graphics/Model.h" |
---|
[10336] | 9 | |
---|
| 10 | |
---|
| 11 | namespace orxonox{ |
---|
| 12 | RegisterClass(GravityBomb); |
---|
| 13 | |
---|
[10435] | 14 | const float GravityBomb::LIFETIME = 5; |
---|
| 15 | |
---|
[10336] | 16 | GravityBomb::GravityBomb(Context* context): |
---|
[10341] | 17 | BasicProjectile(), |
---|
| 18 | MovableEntity(context), |
---|
| 19 | RadarViewable(this,static_cast<WorldEntity*>(this)) |
---|
[10336] | 20 | { |
---|
| 21 | RegisterObject(GravityBomb); |
---|
| 22 | |
---|
[10391] | 23 | this->setMass(10.0); |
---|
| 24 | this->isDetonated_ = false; |
---|
[10341] | 25 | if (GameMode::isMaster()) |
---|
| 26 | { |
---|
[10369] | 27 | //Define CollisionType of the bomb |
---|
[10435] | 28 | this->timeToLife_= LIFETIME; |
---|
[10369] | 29 | this->setCollisionResponse(false); |
---|
[10391] | 30 | this->setCollisionType(WorldEntity::Dynamic); |
---|
[10341] | 31 | this->enableCollisionCallback(); |
---|
[10336] | 32 | |
---|
[10341] | 33 | //Add Collision Shape |
---|
| 34 | SphereCollisionShape* collisionShape = new SphereCollisionShape(context); |
---|
[10369] | 35 | collisionShape->setRadius(1.0); |
---|
[10341] | 36 | this->attachCollisionShape(collisionShape); |
---|
| 37 | |
---|
| 38 | //Create Bomb Model |
---|
[10435] | 39 | Model* rocketModel = new Model(this->getContext()); |
---|
| 40 | rocketModel->setMeshSource("GravityBombRocket.mesh"); //Demo Model from SimpleRocket |
---|
| 41 | rocketModel->scale(3.0f); |
---|
| 42 | this->attach(rocketModel); |
---|
[10341] | 43 | |
---|
[10435] | 44 | Model* bombModel = new Model(this->getContext()); |
---|
| 45 | bombModel->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket |
---|
| 46 | bombModel->scale(3.0f); |
---|
| 47 | this->attach(bombModel); |
---|
| 48 | |
---|
[10341] | 49 | } |
---|
[10336] | 50 | } |
---|
| 51 | |
---|
| 52 | GravityBomb::~GravityBomb(){} |
---|
| 53 | |
---|
| 54 | void GravityBomb::tick(float dt) |
---|
| 55 | { |
---|
[10391] | 56 | timeToLife_ -= dt; |
---|
| 57 | if(timeToLife_ < 0) |
---|
[10341] | 58 | { |
---|
[10369] | 59 | orxout(debug_output) << "bomb has stoped moving" <<endl; |
---|
[10341] | 60 | setVelocity(Vector3::ZERO); |
---|
| 61 | setAcceleration(Vector3::ZERO); |
---|
[10436] | 62 | isDetonated_ = true; |
---|
[10341] | 63 | } |
---|
[10369] | 64 | else |
---|
| 65 | { |
---|
[10391] | 66 | orxout(debug_output)<< "Time to live:" << timeToLife_ <<endl; |
---|
[10369] | 67 | destroyCheck(); |
---|
| 68 | } |
---|
[10391] | 69 | if(isDetonated_) detonate(); |
---|
[10436] | 70 | else SUPER(GravityBomb, tick, dt); |
---|
[10336] | 71 | } |
---|
| 72 | |
---|
| 73 | bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
| 74 | { |
---|
[10391] | 75 | if(otherObject != getShooter()) |
---|
| 76 | { |
---|
| 77 | orxout(debug_output) << "collides" << endl; |
---|
| 78 | processCollision(otherObject, contactPoint,cs); |
---|
| 79 | isDetonated_ = true; |
---|
| 80 | return true; |
---|
| 81 | } |
---|
| 82 | else{ |
---|
| 83 | orxout(debug_output) << "collided with shooter. Has no effect..." << endl; |
---|
| 84 | return false; |
---|
| 85 | } |
---|
[10336] | 86 | } |
---|
[10341] | 87 | |
---|
| 88 | void GravityBomb::detonate() |
---|
| 89 | { |
---|
| 90 | GravityBombField* field = new GravityBombField(this->getContext()); |
---|
[10435] | 91 | field->setShooter(this->getShooter()); |
---|
[10391] | 92 | field->setPosition(getPosition()); |
---|
| 93 | orxout(debug_output) << "detonating. Creating GravityBombField." <<endl; |
---|
| 94 | orxout(debug_output) << "Field is at Position: " << getPosition() << endl; |
---|
[10369] | 95 | this->destroy(); |
---|
[10341] | 96 | } |
---|
[10336] | 97 | } |
---|
| 98 | |
---|
| 99 | |
---|