Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.cc @ 10422

Last change on this file since 10422 was 10409, checked in by meggiman, 10 years ago

Started implementing Particle effect. Force Field explodes at end of life.

File size: 2.0 KB
RevLine 
[10341]1/*
2 * GravityBombField.cc
3 *
4 *  Created on: Apr 2, 2015
5 *      Author: meggiman
6 */
7
8#include "GravityBombField.h"
[10391]9#include "graphics/Model.h"
[10341]10
11namespace orxonox{
12        RegisterClass(GravityBombField);
13
[10409]14        const float GravityBombField::FORCE_FIELD_LIFETIME = 20;
15        const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250;
[10391]16        const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -500;
[10341]17
[10409]18        GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this))
[10341]19        {
[10369]20                RegisterObject(GravityBombField);
[10341]21                lifetime_=FORCE_FIELD_LIFETIME;
[10409]22                forceStrength_ = FORCE_SPHERE_START_STRENGTH;
23                forceSphereRadius_ = FORCE_SPHERE_START_RADIUS;
24                fieldExploded_ = false;
25
[10341]26                setVelocity(FORCE_SPHERE_START_STRENGTH);
[10409]27                setDiameter(2*FORCE_SPHERE_START_RADIUS);
28                setMode(modeSphere_s);
[10391]29                setCollisionResponse(false);
30
[10409]31                this->setRadarObjectColour(ColourValue(0.2, 0.2, 1.0,1)); // Blue
32                this->setRadarObjectShape(RadarViewable::Dot);
33                this->setRadarObjectScale(0.5f);
34
[10391]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);
[10409]40
41                this->particleSphere_ = new ParticleEmitter(this->getContext());
42                this->attach(this->particleSphere_);
43
44                particleSphere_->setSource("Orxonox/GravityBombField");
[10341]45        }
46
47        GravityBombField::~GravityBombField(){}
48
49        void GravityBombField::tick(float dt)
50        {
[10369]51                SUPER(GravityBombField,tick,dt);
[10341]52                lifetime_-=dt;
[10409]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
[10341]65                if(lifetime_ < 0)
66                {
[10391]67                        orxout(debug_output) << "Timeout. Destroying field." << endl;
[10341]68                        this->destroy();
69                }
70        }
71
72        void GravityBombField::destroy()
73        {
74                //Animation
[10369]75                ForceField::destroy();
[10341]76        }
77
78}
Note: See TracBrowser for help on using the repository browser.