Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2015, 7:33:37 PM (9 years ago)
Author:
meggiman
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.cc

    r10435 r10455  
    33 *
    44 *  Created on: Apr 2, 2015
    5  *      Author: meggiman
     5 *      Author: Manuel Eggimann
    66 */
    77
     
    1212        RegisterClass(GravityBombField);
    1313
    14         const float GravityBombField::FORCE_FIELD_LIFETIME = 20;
     14        //Change these constants to alter the behaviour of the field.
     15       
     16        const float GravityBombField::FORCE_FIELD_LIFETIME = 15;
    1517        const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250;
    1618        const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -500;
    17         const float GravityBombField::PEAK_EXPLOSION_FORCE = 1e6;
     19        const float GravityBombField::PEAK_EXPLOSION_FORCE = 5e4;
    1820        const float GravityBombField::FORCE_FIELD_EXPLOSION_DAMMAGE = 100;
    1921        const float GravityBombField::EXPLOSION_DURATION = 1;
    20         const float GravityBombField::EXPLOSION_RADIUS = 400;
     22        const float GravityBombField::EXPLOSION_RADIUS = 600;
    2123        const float GravityBombField::PEAK_ANGULAR_VELOCITY = 20;
     24        const float GravityBombField::CENTRE_MODEL_END_SIZE = 1.5;
    2225
    2326        GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this))
    2427        {
    2528                RegisterObject(GravityBombField);
     29                //Initialize variable with their initial values.
    2630                lifetime_=FORCE_FIELD_LIFETIME;
    2731                forceStrength_ = FORCE_SPHERE_START_STRENGTH;
    2832                forceSphereRadius_ = FORCE_SPHERE_START_RADIUS;
     33                modelScaling_ = 1;
    2934                fieldExploded_ = false;
    3035
     
    3439                setCollisionResponse(false);
    3540
     41                //Make the Field visible on Radar and minimap.
    3642                this->setRadarObjectColour(ColourValue(0.2, 0.2, 1.0,1)); // Blue
    3743                this->setRadarObjectShape(RadarViewable::Dot);
    3844                this->setRadarObjectScale(0.5f);
     45               
    3946
    4047                //Attach Model
    4148                Model* model = new Model(this->getContext());
    4249                model->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket
    43                 model->scale(3.0f);
     50                model->scale(2.5f);
    4451                bombModel_ = new MovableEntity(context);
    4552                bombModel_->attach(model);
    4653                this->attach(bombModel_);
    4754
    48                 Backlight* centreLight = new Backlight(context);
    49                 centreLight->setColour(ColourValue(0.9,0.5,0.5,1));
    50                 centreLight->setScale(1.0);
    51                 centreLight->setTrailMaterial("Trail/backlighttrail");
    52                 centreLight->setMaterial("Examples/Flare");
    53                 centreLight->setLifetime(20);
    54                 bombModel_->attach(centreLight);
     55                //Add a Backlight to the centre.
     56                centreLight_ = new Backlight(context);
     57                centreLight_->setColour(ColourValue(0.2,0.9,0.2,1));
     58                centreLight_->setScale(0.3);
     59                centreLight_->setTrailMaterial("Trail/backlighttrail");
     60                centreLight_->setMaterial("Examples/Flare");
     61                centreLight_->setLifetime(20);
     62                bombModel_->attach(centreLight_);
    5563
     64                //Let the Bomb Modell in the centre rotate in a random direction.
    5665                Vector3 randomRotation;
    5766                srand(time(NULL));
     
    6473                //Add Collision Shape
    6574                SphereCollisionShape* collisionShape = new SphereCollisionShape(context);
    66                 collisionShape->setRadius(3.0);
     75                collisionShape->setRadius(10.0);
    6776                this->attachCollisionShape(collisionShape);
    6877
     78                //Add particle effect to visualize the force field.
    6979                this->particleSphere_ = new ParticleEmitter(this->getContext());
    7080                this->attach(this->particleSphere_);
    7181                particleSphere_->setSource("Orxonox/GravityBombField");
     82
     83                //Add a sound effect to the field.
     84                WorldSound* fieldSound = new WorldSound(context);
     85                fieldSound->setSource("sounds/GravityField.ogg");
     86                fieldSound->setLooping(true);
     87                fieldSound->setVolume(1.0);
     88                this->attach(fieldSound);
     89                fieldSound->play();
    7290        }
    7391
    7492        GravityBombField::~GravityBombField(){}
    7593
     94       
    7695        void GravityBombField::tick(float dt)
    7796        {
     
    7998                lifetime_-=dt;
    8099
    81                 if(lifetime_ > EXPLOSION_DURATION)
     100                if(lifetime_ > EXPLOSION_DURATION)//If field is still alive, make it smaller and stronger.
    82101                {
     102                        modelScaling_ += ((CENTRE_MODEL_END_SIZE-1) / FORCE_FIELD_LIFETIME)*dt;
    83103                        forceStrength_ *= (1+dt/10);
    84104                        forceSphereRadius_ = FORCE_SPHERE_START_RADIUS*(1-((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME)*((FORCE_FIELD_LIFETIME-lifetime_)/FORCE_FIELD_LIFETIME));
     
    86106                else if(lifetime_ > 0)
    87107                {
    88                         if (!fieldExploded_)
     108                        if (!fieldExploded_) // Start the field explosion if it has not been started yet.
    89109                        {
    90                                 forceStrength_ = PEAK_EXPLOSION_FORCE;
     110                                forceStrength_ = pow((EXPLOSION_DURATION + lifetime_),4)/EXPLOSION_DURATION * PEAK_EXPLOSION_FORCE;
    91111                                fieldExploded_ = true;
    92112
     113                                //Add particle effect to visualize explosion
    93114                                explosionCross_ = new ParticleEmitter(this->getContext());
     115                                explosionCross_->setSource("Orxonox/FieldExplosion");
     116                                explosionCross_->setOrientation(rand(), rand(), rand(), rand());
     117                                explosionCross_->setScale(0.7);
    94118                                this->attach(explosionCross_);
    95                                 explosionCross_->setSource("Orxonox/FieldExplosion");
     119
     120                                //Add explosion sound effect.
     121                                explosionSound_ = new WorldSound(getContext());
     122                                explosionSound_->setSource("sounds/GravityFieldExplosion.ogg");
     123                                explosionSound_->setVolume(1.0);
     124                                explosionSound_->play();
    96125                        }
    97126
     127                        //Check if any pawn is inside the shockwave and hit it with dammage proportional to the distance between explosion centre and pawn. Make sure, the same pawn is damaged only once.
    98128                        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
    99129                        {
    100130                                Vector3 distanceVector = it->getWorldPosition()-this->getWorldPosition();
    101                                  orxout(debug_output) << "Found Pawn:" << it->getWorldPosition() << endl;
     131                                 //orxout(debug_output) << "Found Pawn:" << it->getWorldPosition() << endl;
    102132                                if(distanceVector.length()< forceSphereRadius_)
    103133                                 {
    104                                          orxout(debug_output) << "Force sphere radius is: " << forceSphereRadius_ << " Distance to Pawn is: " << distanceVector.length();
     134                                         //orxout(debug_output) << "Force sphere radius is: " << forceSphereRadius_ << " Distance to Pawn is: " << distanceVector.length();
    105135                                         if (std::find(victimsAlreadyDamaged_.begin(),victimsAlreadyDamaged_.end(),*it) == victimsAlreadyDamaged_.end())
    106136                                         {
    107                                                  orxout(debug_output) << "Found Pawn to damage: " << it->getWorldPosition() << endl;
     137                                                 //orxout(debug_output) << "Found Pawn to damage: " << it->getWorldPosition() << endl;
    108138                                                 float damage = FORCE_FIELD_EXPLOSION_DAMMAGE*(1-distanceVector.length()/EXPLOSION_RADIUS);
    109                                                  orxout(debug_output) << "Damage: " << damage << endl;
     139                                                 //orxout(debug_output) << "Damage: " << damage << endl;
    110140                                                 it->hit(shooter_, it->getWorldPosition(), NULL, damage, 0,0);
    111 //                                               it->removeHealth(damage);
    112141                                                 victimsAlreadyDamaged_.push_back(*it);
    113142                                         }
     
    118147                        explosionCross_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS);
    119148                }
    120                 else if (lifetime_ > -4)
     149                else if (lifetime_ > -6) //The field has to exist for 6 more seconds for the particles of the particle effect to vanish smoothly.
    121150                {
     151                        //Make the bomb model invisible, let the strength of the field be zero and remove all particle emitters so the particle effect will slowly vanish.
    122152                        bombModel_->setVisible(false);
    123153                        this->setRadarVisibility(false);
     
    127157                        explosionCross_->getParticleInterface()->removeAllEmitters();
    128158                }
    129 
     159               
    130160                setDiameter(forceSphereRadius_*2);
    131161                setVelocity(forceStrength_);
    132                 particleSphere_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS);
     162                if(lifetime_>0) particleSphere_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS);
     163                bombModel_->setScale(modelScaling_);
    133164
    134165                if (lifetime_ <= -4)
     
    141172        void GravityBombField::destroy()
    142173        {
    143                 //Animation
    144174                ForceField::destroy();
    145175        }
Note: See TracChangeset for help on using the changeset viewer.