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 | |
---|
13 | const float GravityBomb::INITIAL_VELOCITY = 20; |
---|
14 | const float GravityBomb::SLOW_DOWN_RATIO = 2; |
---|
15 | |
---|
16 | GravityBomb::GravityBomb(Context* context): |
---|
17 | BasicProjectile(), |
---|
18 | MovableEntity(context), |
---|
19 | RadarViewable(this,static_cast<WorldEntity*>(this)) |
---|
20 | { |
---|
21 | RegisterObject(GravityBomb); |
---|
22 | |
---|
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(); |
---|
32 | |
---|
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 | } |
---|
42 | } |
---|
43 | |
---|
44 | GravityBomb::~GravityBomb(){} |
---|
45 | |
---|
46 | void GravityBomb::tick(float dt) |
---|
47 | { |
---|
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(); |
---|
56 | } |
---|
57 | |
---|
58 | bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
59 | { |
---|
60 | detonate(); |
---|
61 | processCollision(otherObject, contactPoint,cs); |
---|
62 | return true; |
---|
63 | } |
---|
64 | |
---|
65 | void GravityBomb::detonate() |
---|
66 | { |
---|
67 | GravityBombField* field = new GravityBombField(this->getContext()); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | |
---|