Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 4, 2019, 5:13:42 PM (6 years ago)
Author:
cwaupoti
Message:

added working HoverGun

Location:
code/branches/Boxhead_FS19/src/modules/weapons/projectiles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.cc

    r12273 r12284  
    2121 *
    2222 *   Author:
    23  *      Joel Smely
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      simonmie
    2626 *
    2727 */
     
    3434#include "HoverGunProjectile.h"
    3535
     36#include "core/config/ConfigValueIncludes.h"
    3637#include "core/CoreIncludes.h"
     38#include "core/GameMode.h"
    3739#include "core/command/Executor.h"
    38 #include "util/Convert.h"
     40
     41#include "worldentities/pawns/Pawn.h"
    3942
    4043namespace orxonox
     
    4245    RegisterClass(HoverGunProjectile);
    4346
    44     HoverGunProjectile::HoverGunProjectile(Context* context) : BillboardProjectile(context)
     47    HoverGunProjectile::HoverGunProjectile(Context* context) : MovableEntity(context), BasicProjectile()
    4548    {
    4649        RegisterObject(HoverGunProjectile);
    4750
    48         this->textureIndex_ = 1;
    49         this->setMass(0.1f);
    50         this->setCollisionType(CollisionType::Dynamic);
    51         this->maxTextureIndex_ = 8;
    52         this->textureTimer_.setTimer(0.01f, true, createExecutor(createFunctor(&HoverGunProjectile::changeTexture, this)));
     51        this->setConfigValues();
    5352
    54         registerVariables();
     53        // Get notification about collisions
     54        if (GameMode::isMaster())
     55        {
     56            this->setMass(0.0000000001f);
     57            this->enableCollisionCallback();
     58            this->setCollisionResponse(false);
     59            this->setCollisionType(CollisionType::Dynamic);
     60
     61            // Create a sphere collision shape and attach it to the projectile.
     62            collisionShape_ = new SphereCollisionShape(this->getContext());
     63            setCollisionShapeRadius(2.0f);
     64            this->attachCollisionShape(collisionShape_);
     65
     66            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
     67        }
    5568    }
    5669
    57     void HoverGunProjectile::registerVariables()
     70    HoverGunProjectile::~HoverGunProjectile()
    5871    {
    59         registerVariable(this->materialBase_);
    6072    }
    6173
    62     /**
    63     @brief
    64         Set the material.
    65     @param material
    66         The name of the material. Material names with 1 to 8 appended must exist.
    67     */
    68     void HoverGunProjectile::setMaterial(const std::string& material)
     74    void HoverGunProjectile::setConfigValues()
    6975    {
    70         this->materialBase_ = material;
    71 
    72         BillboardProjectile::setMaterial(material + multi_cast<std::string>(this->textureIndex_));
     76        SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive");
    7377    }
    7478
    75     /**
    76     @brief
    77         Change the texture.
    78     */
    79     void HoverGunProjectile::changeTexture()
     79
     80    bool HoverGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
    8081    {
    81         this->textureIndex_++;
    82         if (this->textureIndex_ > this->maxTextureIndex_)
    83             this->textureIndex_ = 1;
     82        return this->processCollision(otherObject, contactPoint, cs);
     83    }
    8484
    85         this->setMaterial(this->materialBase_);
     85    void HoverGunProjectile::setCollisionShapeRadius(float radius)
     86    {
     87        if (collisionShape_ != nullptr && radius > 0)
     88        {
     89            collisionShape_->setRadius(radius);
     90        }       
    8691    }
    8792}
  • code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.h

    r12274 r12284  
    2121 *
    2222 *   Author:
    23  *      Joel Smely
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      simonmie
    2626 *
    2727 */
     
    3737#include "weapons/WeaponsPrereqs.h"
    3838
    39 #include <string>
    4039#include "tools/Timer.h"
    41 #include "BillboardProjectile.h"
     40#include "worldentities/MovableEntity.h"
     41#include "objects/collisionshapes/SphereCollisionShape.h"
     42
     43#include "BasicProjectile.h"
    4244
    4345namespace orxonox
     
    4648    /**
    4749    @brief
    48         The HoverGunProjectile is a projectile that is represented by a looped series of billboards.
    49        
     50        Represents all 'standard' projectiles.
     51
    5052    @author
    51         Joel Smely
     53        Fabian 'x3n' Landau
     54    @author
     55        Simon Miescher
    5256    @ingroup WeaponsProjectiles
    5357    */
    54     class _WeaponsExport HoverGunProjectile : public BillboardProjectile
     58    class _WeaponsExport HoverGunProjectile : public MovableEntity, public BasicProjectile
    5559    {
    5660        public:
    5761            HoverGunProjectile(Context* context);
    58             virtual ~HoverGunProjectile() {}
     62            virtual ~HoverGunProjectile();
    5963
    60             virtual void setMaterial(const std::string& material) override;
     64            void setConfigValues();
    6165
    62 /**
    63     @file LightningGunProjectile.h
    64     @brief Definition of the LightningGunProjectile class.
    65 */
     66           
     67            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) override;
    6668
    67 #ifndef _HoverGunProjectile_H__
    68 #define _HoverGunProjectile_H__
    69 
    70 #include "weapons/WeaponsPrereqs.h"
    71 
    72 #include <string>
    73 #include "tools/Timer.h"
    74 #include "BillboardProjectile.h"
    75 
    76 namespace orxonox
    77 {
    78 
    79     /**
    80     @brief
    81         The LightningGunProjectile is a projectile that is represented by a looped series of billboards.
    82        
    83     @author
    84         Joel Smely
    85     @ingroup WeaponsProjectiles
    86     */
    87     class _WeaponsExport HoverGunProjectile : public BillboardProjectile
    88     {
    89         public:
    90             HoverGunProjectile(Context* context);
    91             virtual ~HoverGunProjectile() {}
    92 
    93             virtual void setMaterial(const std::string& material) override;
     69        protected:
     70            virtual void setCollisionShapeRadius(float radius);
     71            float lifetime_; //!< The time the projectile exists.
    9472
    9573        private:
    96             void registerVariables();
    97             void changeTexture();
    98            
    99             unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture)
    100             unsigned int maxTextureIndex_; //!< The maximal index.
    101             Timer textureTimer_; //!< A timer that loops and changes textures each time it expires.
    102             std::string materialBase_; //!< The base name of the material.
     74            Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out.
     75            WeakPtr<SphereCollisionShape> collisionShape_; // The collision shape of the projectile.
    10376    };
    10477}
    10578
    106 #endif /* _HoverGunProjectile_H__ */
     79#endif /* _Projectile_H__ */
Note: See TracChangeset for help on using the changeset viewer.