1 | /* |
---|
2 | * GravityBombField.cc |
---|
3 | * |
---|
4 | * Created on: Apr 2, 2015 |
---|
5 | * Author: meggiman |
---|
6 | */ |
---|
7 | |
---|
8 | #include "GravityBombField.h" |
---|
9 | #include "graphics/Model.h" |
---|
10 | |
---|
11 | namespace orxonox{ |
---|
12 | RegisterClass(GravityBombField); |
---|
13 | |
---|
14 | const float GravityBombField::FORCE_FIELD_LIFETIME = 20; |
---|
15 | const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250; |
---|
16 | const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -500; |
---|
17 | |
---|
18 | GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this)) |
---|
19 | { |
---|
20 | RegisterObject(GravityBombField); |
---|
21 | lifetime_=FORCE_FIELD_LIFETIME; |
---|
22 | forceStrength_ = FORCE_SPHERE_START_STRENGTH; |
---|
23 | forceSphereRadius_ = FORCE_SPHERE_START_RADIUS; |
---|
24 | fieldExploded_ = false; |
---|
25 | |
---|
26 | setVelocity(FORCE_SPHERE_START_STRENGTH); |
---|
27 | setDiameter(2*FORCE_SPHERE_START_RADIUS); |
---|
28 | setMode(modeSphere_s); |
---|
29 | setCollisionResponse(false); |
---|
30 | |
---|
31 | this->setRadarObjectColour(ColourValue(0.2, 0.2, 1.0,1)); // Blue |
---|
32 | this->setRadarObjectShape(RadarViewable::Dot); |
---|
33 | this->setRadarObjectScale(0.5f); |
---|
34 | |
---|
35 | //Attach Demo Model for debuging. |
---|
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 | this->particleSphere_ = new ParticleEmitter(this->getContext()); |
---|
42 | this->attach(this->particleSphere_); |
---|
43 | |
---|
44 | particleSphere_->setSource("Orxonox/GravityBombField"); |
---|
45 | } |
---|
46 | |
---|
47 | GravityBombField::~GravityBombField(){} |
---|
48 | |
---|
49 | void GravityBombField::tick(float dt) |
---|
50 | { |
---|
51 | SUPER(GravityBombField,tick,dt); |
---|
52 | lifetime_-=dt; |
---|
53 | forceStrength_ *= (1+dt/10); |
---|
54 | if(lifetime_ < 0.2 && !fieldExploded_) |
---|
55 | { |
---|
56 | forceStrength_ *= -2; |
---|
57 | forceSphereRadius_ *= 2; |
---|
58 | fieldExploded_ = true; |
---|
59 | orxout(debug_output) << "Field exploded. Inverting Force." << endl; |
---|
60 | } |
---|
61 | |
---|
62 | setDiameter(forceSphereRadius_*2); |
---|
63 | setVelocity(forceStrength_); |
---|
64 | |
---|
65 | if(lifetime_ < 0) |
---|
66 | { |
---|
67 | orxout(debug_output) << "Timeout. Destroying field." << endl; |
---|
68 | this->destroy(); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | void GravityBombField::destroy() |
---|
73 | { |
---|
74 | //Animation |
---|
75 | ForceField::destroy(); |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|