- Timestamp:
- Apr 4, 2019, 3:51:04 PM (6 years ago)
- Location:
- code/branches/Boxhead_FS19/src/modules/weapons/projectiles
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Boxhead_FS19/src/modules/weapons/projectiles/CMakeLists.txt
r12191 r12273 15 15 MineProjectile.cc 16 16 WagnisProjectile.cc 17 HoverGunProjectile.cc 17 18 ) -
code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.cc
r12262 r12273 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Joel Smely 24 24 * Co-authors: 25 * simonmie25 * ... 26 26 * 27 27 */ 28 28 29 29 /** 30 @file Projectile.h31 @brief Implementation of the Projectile class.30 @file HoverGunProjectile.h 31 @brief Implementation of the HoverGunProjectile class. 32 32 */ 33 33 34 34 #include "HoverGunProjectile.h" 35 35 36 #include "core/config/ConfigValueIncludes.h"37 36 #include "core/CoreIncludes.h" 38 #include "core/GameMode.h"39 37 #include "core/command/Executor.h" 40 41 #include "worldentities/pawns/Pawn.h" 38 #include "util/Convert.h" 42 39 43 40 namespace orxonox … … 45 42 RegisterClass(HoverGunProjectile); 46 43 47 HoverGunProjectile::HoverGunProjectile(Context* context) : MovableEntity(context), BasicProjectile()44 HoverGunProjectile::HoverGunProjectile(Context* context) : BillboardProjectile(context) 48 45 { 49 46 RegisterObject(HoverGunProjectile); 50 47 51 this->setConfigValues(); 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))); 52 53 53 // Get notification about collisions 54 if (GameMode::isMaster()) 55 { 56 this->setMass(0.1f); 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(8.0f); 64 this->attachCollisionShape(collisionShape_); 65 66 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this))); 67 } 54 registerVariables(); 68 55 } 69 56 70 HoverGunProjectile::~HoverGunProjectile()57 void HoverGunProjectile::registerVariables() 71 58 { 59 registerVariable(this->materialBase_); 72 60 } 73 61 74 void HoverGunProjectile::setConfigValues() 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) 75 69 { 76 SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive"); 70 this->materialBase_ = material; 71 72 BillboardProjectile::setMaterial(material + multi_cast<std::string>(this->textureIndex_)); 77 73 } 78 74 79 void HoverGunProjectile::tick(float dt) 75 /** 76 @brief 77 Change the texture. 78 */ 79 void HoverGunProjectile::changeTexture() 80 80 { 81 SUPER(Projectile, tick, dt); 81 this->textureIndex_++; 82 if (this->textureIndex_ > this->maxTextureIndex_) 83 this->textureIndex_ = 1; 82 84 83 if (!this->isActive()) 84 return; 85 86 this->destroyCheck(); 87 } 88 89 bool HoverGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) 90 { 91 return this->processCollision(otherObject, contactPoint, cs); 92 } 93 94 void HoverGunProjectile::setCollisionShapeRadius(float radius) 95 { 96 if (collisionShape_ != nullptr && radius > 0) 97 { 98 collisionShape_->setRadius(radius); 99 } 85 this->setMaterial(this->materialBase_); 100 86 } 101 87 } -
code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.h
r12262 r12273 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Joel Smely 24 24 * Co-authors: 25 * simonmie25 * ... 26 26 * 27 27 */ 28 28 29 29 /** 30 @file Projectile.h31 @brief Definition of the Projectile class.30 @file HoverGunProjectile.h 31 @brief Definition of the HoverGunProjectile class. 32 32 */ 33 33 … … 37 37 #include "weapons/WeaponsPrereqs.h" 38 38 39 #include <string> 39 40 #include "tools/Timer.h" 40 #include "worldentities/MovableEntity.h" 41 #include "objects/collisionshapes/SphereCollisionShape.h" 42 43 #include "BasicProjectile.h" 41 #include "BillboardProjectile.h" 44 42 45 43 namespace orxonox … … 48 46 /** 49 47 @brief 50 Represents all 'standard' projectiles.51 48 The HoverGunProjectile is a projectile that is represented by a looped series of billboards. 49 52 50 @author 53 Fabian 'x3n' Landau 54 @author 55 Simon Miescher 51 Joel Smely 56 52 @ingroup WeaponsProjectiles 57 53 */ 58 class _WeaponsExport HoverGunProjectile : public MovableEntity, public BasicProjectile54 class _WeaponsExport HoverGunProjectile : public BillboardProjectile 59 55 { 60 56 public: 61 57 HoverGunProjectile(Context* context); 62 virtual ~HoverGunProjectile() ;58 virtual ~HoverGunProjectile() {} 63 59 64 void setConfigValues(); 65 66 virtual void tick(float dt) override; 67 virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) override; 68 69 protected: 70 virtual void setCollisionShapeRadius(float radius); 71 float lifetime_; //!< The time the projectile exists. 60 virtual void setMaterial(const std::string& material) override; 72 61 73 62 private: 74 Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out. 75 WeakPtr<SphereCollisionShape> collisionShape_; // The collision shape of the projectile. 63 void registerVariables(); 64 void changeTexture(); 65 66 unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture) 67 unsigned int maxTextureIndex_; //!< The maximal index. 68 Timer textureTimer_; //!< A timer that loops and changes textures each time it expires. 69 std::string materialBase_; //!< The base name of the material. 76 70 }; 77 71 } 78 72 79 #endif /* _ Projectile_H__ */73 #endif /* _HoverGunProjectile_H__ */
Note: See TracChangeset
for help on using the changeset viewer.