Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10435 for code


Ignore:
Timestamp:
May 7, 2015, 5:43:36 PM (9 years ago)
Author:
meggiman
Message:

Added new models and fixed dammage bug. Bomb now fully working.

Location:
code/branches/weaponFS15
Files:
2 added
6 edited

Legend:

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

    r10391 r10435  
    1212        RegisterClass(GravityBomb);
    1313
     14        const float GravityBomb::LIFETIME = 5;
     15
    1416        GravityBomb::GravityBomb(Context* context):
    1517                                BasicProjectile(),
     
    2426                        {
    2527                                //Define CollisionType of the bomb
    26                                 this->timeToLife_= 5;
     28                                this->timeToLife_= LIFETIME;
    2729                                this->setCollisionResponse(false);
    2830                                this->setCollisionType(WorldEntity::Dynamic);
     
    3537
    3638                                //Create Bomb Model
    37                     Model* model = new Model(this->getContext());
    38                     model->setMeshSource("rocket.mesh"); //Demo Model from SimpleRocket
    39                     model->scale(0.7f);
    40                     this->attach(model);
     39                    Model* rocketModel = new Model(this->getContext());
     40                    rocketModel->setMeshSource("GravityBombRocket.mesh"); //Demo Model from SimpleRocket
     41                    rocketModel->scale(3.0f);
     42                    this->attach(rocketModel);
     43
     44                    Model* bombModel =  new Model(this->getContext());
     45                    bombModel->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket
     46                                bombModel->scale(3.0f);
     47                                this->attach(bombModel);
    4148
    4249                        }
     
    8289        {
    8390                GravityBombField* field = new GravityBombField(this->getContext());
     91                field->setShooter(this->getShooter());
    8492                field->setPosition(getPosition());
    8593                orxout(debug_output) << "detonating. Creating GravityBombField." <<endl;
  • code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBomb.h

    r10391 r10435  
    6565                        void detonate();
    6666                private:
     67                static const float LIFETIME;
     68
    6769                bool isDetonated_; //Used to check whether the Bomb has to be destroyed during next tick.
    6870                float timeToLife_; //Time the bomb flies before it explodes.
  • code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.cc

    r10409 r10435  
    1515        const float GravityBombField::FORCE_SPHERE_START_RADIUS = 250;
    1616        const float GravityBombField::FORCE_SPHERE_START_STRENGTH = -500;
     17        const float GravityBombField::PEAK_EXPLOSION_FORCE = 1e6;
     18        const float GravityBombField::FORCE_FIELD_EXPLOSION_DAMMAGE = 100;
     19        const float GravityBombField::EXPLOSION_DURATION = 1;
     20        const float GravityBombField::EXPLOSION_RADIUS = 400;
     21        const float GravityBombField::PEAK_ANGULAR_VELOCITY = 20;
    1722
    1823        GravityBombField::GravityBombField(Context* context) : ForceField(context),RadarViewable(this, static_cast<WorldEntity*>(this))
     
    3338                this->setRadarObjectScale(0.5f);
    3439
    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                //Attach Model
     41                Model* model = new Model(this->getContext());
     42                model->setMeshSource("GravityBomb.mesh"); //Demo Model from SimpleRocket
     43                model->scale(3.0f);
     44                bombModel_ = new MovableEntity(context);
     45                bombModel_->attach(model);
     46                this->attach(bombModel_);
     47
     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
     56                Vector3 randomRotation;
     57                srand(time(NULL));
     58                randomRotation.x = rand();
     59                randomRotation.y = rand();
     60                randomRotation.y = rand();
     61                randomRotation.normalise();
     62                bombModel_->setAngularAcceleration(randomRotation*(PEAK_ANGULAR_VELOCITY/FORCE_FIELD_LIFETIME));
     63
     64                //Add Collision Shape
     65                SphereCollisionShape* collisionShape = new SphereCollisionShape(context);
     66                collisionShape->setRadius(3.0);
     67                this->attachCollisionShape(collisionShape);
    4068
    4169                this->particleSphere_ = new ParticleEmitter(this->getContext());
    4270                this->attach(this->particleSphere_);
    43 
    4471                particleSphere_->setSource("Orxonox/GravityBombField");
    4572        }
     
    5178                SUPER(GravityBombField,tick,dt);
    5279                lifetime_-=dt;
    53                 forceStrength_ *= (1+dt/10);
    54                 if(lifetime_ < 0.2 && !fieldExploded_)
     80
     81                if(lifetime_ > EXPLOSION_DURATION)
    5582                {
    56                         forceStrength_ *= -2;
    57                         forceSphereRadius_ *= 2;
    58                         fieldExploded_ = true;
    59                         orxout(debug_output) << "Field exploded. Inverting Force." << endl;
     83                        forceStrength_ *= (1+dt/10);
     84                        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));
     85                }
     86                else if(lifetime_ > 0)
     87                {
     88                        if (!fieldExploded_)
     89                        {
     90                                forceStrength_ = PEAK_EXPLOSION_FORCE;
     91                                fieldExploded_ = true;
     92
     93                                explosionCross_ = new ParticleEmitter(this->getContext());
     94                                this->attach(explosionCross_);
     95                                explosionCross_->setSource("Orxonox/FieldExplosion");
     96                        }
     97
     98                        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
     99                        {
     100                                Vector3 distanceVector = it->getWorldPosition()-this->getWorldPosition();
     101                                 orxout(debug_output) << "Found Pawn:" << it->getWorldPosition() << endl;
     102                                if(distanceVector.length()< forceSphereRadius_)
     103                                 {
     104                                         orxout(debug_output) << "Force sphere radius is: " << forceSphereRadius_ << " Distance to Pawn is: " << distanceVector.length();
     105                                         if (std::find(victimsAlreadyDamaged_.begin(),victimsAlreadyDamaged_.end(),*it) == victimsAlreadyDamaged_.end())
     106                                         {
     107                                                 orxout(debug_output) << "Found Pawn to damage: " << it->getWorldPosition() << endl;
     108                                                 float damage = FORCE_FIELD_EXPLOSION_DAMMAGE*(1-distanceVector.length()/EXPLOSION_RADIUS);
     109                                                 orxout(debug_output) << "Damage: " << damage << endl;
     110                                                 it->hit(shooter_, it->getWorldPosition(), NULL, damage, 0,0);
     111//                                               it->removeHealth(damage);
     112                                                 victimsAlreadyDamaged_.push_back(*it);
     113                                         }
     114                                 }
     115                        }
     116
     117                        forceSphereRadius_ = EXPLOSION_RADIUS*(1-lifetime_/EXPLOSION_DURATION);
     118                        explosionCross_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS);
     119                }
     120                else if (lifetime_ > -4)
     121                {
     122                        bombModel_->setVisible(false);
     123                        this->setRadarVisibility(false);
     124                        forceStrength_ = 0;
     125                        forceSphereRadius_ = 0.00001;
     126                        particleSphere_->getParticleInterface()->removeAllEmitters();
     127                        explosionCross_->getParticleInterface()->removeAllEmitters();
    60128                }
    61129
    62130                setDiameter(forceSphereRadius_*2);
    63131                setVelocity(forceStrength_);
     132                particleSphere_->setScale(forceSphereRadius_/FORCE_SPHERE_START_RADIUS);
    64133
    65                 if(lifetime_ < 0)
     134                if (lifetime_ <= -4)
    66135                {
    67136                        orxout(debug_output) << "Timeout. Destroying field." << endl;
  • code/branches/weaponFS15/src/modules/weapons/projectiles/GravityBombField.h

    r10409 r10435  
    1717#include "GravityBomb.h"
    1818#include "graphics/ParticleSpawner.h"
    19 
     19#include "tools/ParticleInterface.h"
     20#include <stdlib.h>
     21#include <time.h>
     22#include "graphics/Backlight.h"
    2023
    2124namespace orxonox {
     
    2629        virtual void tick(float dt);
    2730        virtual void destroy();
     31
     32        void setShooter(Pawn* shooter)
     33        { this->shooter_ = shooter; }
     34
     35        Pawn* getShooter()
     36        { return this->shooter_; }
     37
    2838private:
    2939        static const float FORCE_FIELD_LIFETIME;
    3040        static const float FORCE_SPHERE_START_RADIUS;
    3141        static const float FORCE_SPHERE_START_STRENGTH;
     42        static const float FORCE_FIELD_EXPLOSION_DAMMAGE;
     43        static const float EXPLOSION_DURATION;
     44        static const float EXPLOSION_RADIUS;
     45        static const float PEAK_ANGULAR_VELOCITY;
     46        static const float PEAK_EXPLOSION_FORCE;
    3247
    3348        float forceSphereRadius_;
    3449        float forceStrength_;
    3550        float lifetime_;
     51        Vector3 rotationVector_;
    3652        bool fieldExploded_;
    3753        ParticleEmitter * particleSphere_;
    38 
     54        ParticleEmitter * explosionCross_;
     55        std::vector<Pawn*> victimsAlreadyDamaged_;
     56        MovableEntity * bombModel_;
     57        Pawn* shooter_;
    3958};
    4059
  • code/branches/weaponFS15/src/modules/weapons/weaponmodes/GravityBombFire.cc

    r10391 r10435  
    1919        RegisterClass(GravityBombFire);
    2020
     21        const float GravityBombFire::BOMB_VELOCITY = 400.0;
     22
    2123        GravityBombFire::GravityBombFire(Context* context) : WeaponMode(context)
    2224        {
     
    2628                this->bParallelReload_ = false;
    2729                this->damage_ = 0.0f;
    28                 this->speed_ = 100.0f;
     30                this->speed_ = BOMB_VELOCITY;
    2931
    3032                this->setMunitionName("GravityBombMunition");
  • code/branches/weaponFS15/src/modules/weapons/weaponmodes/GravityBombFire.h

    r10391 r10435  
    5858        private:
    5959            float speed_; //!< The initial speed of the bomb when it is launched.
     60            static const float BOMB_VELOCITY;
    6061    };
    6162}
Note: See TracChangeset for help on using the changeset viewer.