1 | /* |
---|
2 | * GravityBomb.cc |
---|
3 | * |
---|
4 | * Created on: Mar 26, 2015 |
---|
5 | * Author: meggiman |
---|
6 | */ |
---|
7 | #include "GravityBomb.h" |
---|
8 | #include "graphics/Model.h" |
---|
9 | |
---|
10 | |
---|
11 | namespace orxonox{ |
---|
12 | RegisterClass(GravityBomb); |
---|
13 | |
---|
14 | GravityBomb::GravityBomb(Context* context): |
---|
15 | BasicProjectile(), |
---|
16 | MovableEntity(context), |
---|
17 | RadarViewable(this,static_cast<WorldEntity*>(this)) |
---|
18 | { |
---|
19 | RegisterObject(GravityBomb); |
---|
20 | |
---|
21 | this->setMass(15.0); |
---|
22 | if (GameMode::isMaster()) |
---|
23 | { |
---|
24 | //Define CollisionType of the bomb |
---|
25 | this->velocityAtLastTick_= 1000; |
---|
26 | this->setCollisionResponse(false); |
---|
27 | this->setCollisionType(WorldEntity::Kinematic); |
---|
28 | this->enableCollisionCallback(); |
---|
29 | |
---|
30 | //Add Collision Shape |
---|
31 | SphereCollisionShape* collisionShape = new SphereCollisionShape(context); |
---|
32 | collisionShape->setRadius(1.0); |
---|
33 | this->attachCollisionShape(collisionShape); |
---|
34 | |
---|
35 | //Create Bomb Model |
---|
36 | Model* model = new Model(this->getContext()); |
---|
37 | model->setMeshSource("rocket.mesh"); //Demo Model from SimpleRocket |
---|
38 | model->scale(0.7f); |
---|
39 | this->attach(model); |
---|
40 | |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | GravityBomb::~GravityBomb(){} |
---|
45 | |
---|
46 | void GravityBomb::tick(float dt) |
---|
47 | { |
---|
48 | velocityAtLastTick_=getVelocity().length(); |
---|
49 | SUPER(GravityBomb,tick,dt); |
---|
50 | if(velocityAtLastTick_ < this->getVelocity().length()) |
---|
51 | { |
---|
52 | orxout(debug_output) << "bomb has stoped moving" <<endl; |
---|
53 | setVelocity(Vector3::ZERO); |
---|
54 | setAcceleration(Vector3::ZERO); |
---|
55 | velocityAtLastTick_=0; |
---|
56 | detonate(); |
---|
57 | orxout(debug_output) << "denoting" <<endl; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | velocityAtLastTick_=getVelocity().length(); |
---|
62 | orxout(debug_output)<< velocityAtLastTick_ <<endl; |
---|
63 | orxout(debug_output) << "acceleration" << getAcceleration().length() <<endl; |
---|
64 | destroyCheck(); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | bool GravityBomb::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) |
---|
69 | { |
---|
70 | orxout(debug_output) << "collides" << endl; |
---|
71 | processCollision(otherObject, contactPoint,cs); |
---|
72 | //detonate(); |
---|
73 | return true; |
---|
74 | } |
---|
75 | |
---|
76 | void GravityBomb::detonate() |
---|
77 | { |
---|
78 | GravityBombField* field = new GravityBombField(this->getContext()); |
---|
79 | orxout(debug_output) << "denoting" <<endl; |
---|
80 | this->destroy(); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|