[10336] | 1 | /* |
---|
| 2 | * GravityBomb.cc |
---|
| 3 | * |
---|
| 4 | * Created on: Mar 26, 2015 |
---|
| 5 | * Author: meggiman |
---|
| 6 | */ |
---|
| 7 | #include "GravityBomb.h" |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | namespace orxonox{ |
---|
| 11 | RegisterClass(GravityBomb); |
---|
| 12 | |
---|
[10341] | 13 | const float GravityBomb::INITIAL_VELOCITY = 20; |
---|
| 14 | const float GravityBomb::SLOW_DOWN_RATIO = 2; |
---|
[10336] | 15 | |
---|
| 16 | GravityBomb::GravityBomb(Context* context): |
---|
[10341] | 17 | BasicProjectile(), |
---|
| 18 | MovableEntity(context), |
---|
| 19 | RadarViewable(this,static_cast<WorldEntity*>(this)) |
---|
[10336] | 20 | { |
---|
| 21 | RegisterObject(GravityBomb); |
---|
| 22 | |
---|
[10341] | 23 | this->setMass(15.0); |
---|
| 24 | if (GameMode::isMaster()) |
---|
| 25 | { |
---|
| 26 | //Define movement of the bomb |
---|
| 27 | this->setVelocity(this->getOrientation()*WorldEntity::FRONT*INITIAL_VELOCITY); |
---|
| 28 | this->velocityAtLastTick_=INITIAL_VELOCITY; |
---|
| 29 | this->setAcceleration(this->getOrientation()*WorldEntity::BACK*SLOW_DOWN_RATIO); |
---|
| 30 | this->setCollisionType(WorldEntity::Dynamic); |
---|
| 31 | this->enableCollisionCallback(); |
---|
[10336] | 32 | |
---|
[10341] | 33 | //Add Collision Shape |
---|
| 34 | SphereCollisionShape* collisionShape = new SphereCollisionShape(context); |
---|
| 35 | collisionShape->setRadius(5.0); |
---|
| 36 | this->attachCollisionShape(collisionShape); |
---|
| 37 | |
---|
| 38 | //Create Bomb Model |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | } |
---|
[10336] | 42 | } |
---|
| 43 | |
---|
| 44 | GravityBomb::~GravityBomb(){} |
---|
| 45 | |
---|
| 46 | void GravityBomb::tick(float dt) |
---|
| 47 | { |
---|
[10341] | 48 | if(velocityAtLastTick_ < this->getVelocity().length()) |
---|
| 49 | { |
---|
| 50 | setVelocity(Vector3::ZERO); |
---|
| 51 | setAcceleration(Vector3::ZERO); |
---|
| 52 | velocityAtLastTick_=0; |
---|
| 53 | detonate(); |
---|
| 54 | } |
---|
| 55 | velocityAtLastTick_=getVelocity().length(); |
---|
[10336] | 56 | } |
---|
| 57 | |
---|
| 58 | bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
| 59 | { |
---|
[10341] | 60 | detonate(); |
---|
| 61 | processCollision(otherObject, contactPoint,cs); |
---|
[10336] | 62 | return true; |
---|
| 63 | } |
---|
[10341] | 64 | |
---|
| 65 | void GravityBomb::detonate() |
---|
| 66 | { |
---|
| 67 | GravityBombField* field = new GravityBombField(this->getContext()); |
---|
| 68 | } |
---|
[10336] | 69 | } |
---|
| 70 | |
---|
| 71 | |
---|