Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 4, 2019, 4:37:19 PM (6 years ago)
Author:
pomselj
Message:

weapon stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/BallGun/BallProjectile.cc

    r12254 r12281  
    3838#include "tools/ParticleInterface.h"
    3939#include "Scene.h"
     40#include "core/command/Executor.h"
     41#include "util/Convert.h"
    4042
    4143namespace orxonox
     
    4345    RegisterClass(BallProjectile);
    4446
    45     BallProjectile::BallProjectile(Context* context) : Projectile(context)
     47    BallProjectile::BallProjectile(Context* context) : BillboardProjectile(context)
    4648    {
    4749        RegisterObject(BallProjectile);
    48 
    49         this->particles_ = nullptr;
     50        orxout() << "It's a bird, it's a plane' it's a BallParticle..." << endl;
     51        this->textureIndex_ = 1;
     52        this->setMass(0.1f);
     53        this->maxTextureIndex_ = 8;
    5054        this->setDestroyAfterCollision(false); //I want the ball to bounce, not to be destroyed
    5155
     
    5357    }
    5458
    55     BallProjectile::~BallProjectile()
     59    void BallProjectile::registerVariables()
    5660    {
    57         if (this->isInitialized() && this->particles_)
    58         {
    59             this->detachOgreObject(this->particles_->getParticleSystem());
    60             delete this->particles_;
    61         }
     61        registerVariable(this->materialBase_);
     62    }
     63
     64    /**
     65    @brief
     66        Set the material.
     67    @param material
     68        The name of the material. Material names with 1 to 8 appended must exist.
     69    */
     70    void BallProjectile::setMaterial(const std::string& material)
     71    {
     72        this->materialBase_ = material;
     73
     74        BillboardProjectile::setMaterial(material + multi_cast<std::string>(this->textureIndex_));
     75    }
     76
     77    /**
     78    @brief
     79        Change the texture.
     80    */
     81    void BallProjectile::changeTexture()
     82    {
     83        this->textureIndex_++;
     84        if (this->textureIndex_ > this->maxTextureIndex_)
     85            this->textureIndex_ = 1;
     86
     87        this->setMaterial(this->materialBase_);
    6288    }
    6389
     
    6894        Vector3 contactPosition = this->getPosition();
    6995
    70         if (positionOtherObject.y < 0) {
    71             this->destroy();
    72         }
    73         else {
     96        //if (positionOtherObject.y < 0) {
     97            //this.destroy()
     98        //}
     99        //else {
     100       
    74101            int distance_X = positionOtherObject.x - contactPosition.x;
     102            int distance_Y = positionOtherObject.y - contactPosition.y;
    75103
    76104            if (distance_X < 0)
    77                 distance_X = -distance_X;
    78 
    79             int distance_Y = positionOtherObject.y - contactPosition.y;   
     105                distance_Y = -distance_Y;
     106   
    80107
    81108            if (distance_Y < 0)
    82                 distance_Y = -distance_Y;
     109                distance_X = -distance_X;
    83110
    84111            if (distance_X < distance_Y)
     
    90117                velocity.y = -velocity.y;
    91118            }
    92         }
     119        //}
    93120    }
    94 
    95121
    96122/**
     
    110136    */
    111137
     138    /*
     139    bool BallProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     140    {
     141        orxout() << "I collided against something" << endl;
     142        return this->processCollision(otherObject, contactPoint, cs);
     143    }
     144    */
     145   
     146    bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape*)
     147    {
    112148
    113     bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
    114     {
    115         if (GameMode::isMaster())
    116         {
     149        orxout() << "wanna bounce..." << endl;
     150        bool result = BasicProjectile::processCollision(otherObject, contactPoint, cs);
     151        Bounce(otherObject, contactPoint, cs);
     152        orxout() << "BOUNCED!" << endl;
    117153
    118             Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is nullptr
    119 
    120             WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
    121             assert(entity); // The projectile must not be a WorldEntity.
    122 
    123             // If visual effects after destruction cause problems, put this block below the effects code block
    124             if (victim)
    125             {
    126                 victim->hit(this->getShooter(), contactPoint, cs, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
    127                 victim->startShieldRechargeCountdown();
    128             }
    129 
    130             // Visual effects for being hit, depending on whether the shield is hit or not
    131             if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed.
    132             {
    133                 // Damping and explosion effect is only played if the victim is no Pawn (see cast above)
    134                 // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health
    135                 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f)))
    136                 {
    137                     {
    138                         ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
    139                         effect->setPosition(entity->getPosition());
    140                         effect->setOrientation(entity->getOrientation());
    141                         effect->setDestroyAfterLife(true);
    142                         effect->setSource("Orxonox/explosion3");
    143                         effect->setLifetime(2.0f);
    144                     }
    145                     // Second effect with same condition
    146                     {
    147                         ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
    148                         effect->setPosition(entity->getPosition());
    149                         effect->setOrientation(entity->getOrientation());
    150                         effect->setDestroyAfterLife(true);
    151                         effect->setSource("Orxonox/smoke4");
    152                         effect->setLifetime(3.0f);
    153                     }
    154                 }
    155 
    156                 // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
    157                 if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f)
    158                 {
    159                     ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
    160                     effect->setDestroyAfterLife(true);
    161                     effect->setSource("Orxonox/Shield");
    162                     effect->setLifetime(0.5f);
    163                     victim->attach(effect);
    164                 }
    165             }
    166 
    167             Bounce(otherObject, contactPoint, cs);
    168 
    169             return true;
    170         }
    171         return false;
     154        return result;
    172155    }
    173156}
Note: See TracChangeset for help on using the changeset viewer.