Changeset 12284 for code/branches/Boxhead_FS19/src/modules
- Timestamp:
- Apr 4, 2019, 5:13:42 PM (6 years ago)
- Location:
- code/branches/Boxhead_FS19/src/modules/weapons
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.cc
r12273 r12284 21 21 * 22 22 * Author: 23 * Joel Smely23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * simonmie 26 26 * 27 27 */ … … 34 34 #include "HoverGunProjectile.h" 35 35 36 #include "core/config/ConfigValueIncludes.h" 36 37 #include "core/CoreIncludes.h" 38 #include "core/GameMode.h" 37 39 #include "core/command/Executor.h" 38 #include "util/Convert.h" 40 41 #include "worldentities/pawns/Pawn.h" 39 42 40 43 namespace orxonox … … 42 45 RegisterClass(HoverGunProjectile); 43 46 44 HoverGunProjectile::HoverGunProjectile(Context* context) : BillboardProjectile(context)47 HoverGunProjectile::HoverGunProjectile(Context* context) : MovableEntity(context), BasicProjectile() 45 48 { 46 49 RegisterObject(HoverGunProjectile); 47 50 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(); 53 52 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 } 55 68 } 56 69 57 void HoverGunProjectile::registerVariables()70 HoverGunProjectile::~HoverGunProjectile() 58 71 { 59 registerVariable(this->materialBase_);60 72 } 61 73 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() 69 75 { 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"); 73 77 } 74 78 75 /** 76 @brief 77 Change the texture. 78 */ 79 void HoverGunProjectile::changeTexture() 79 80 bool HoverGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint) 80 81 { 81 this->textureIndex_++; 82 if (this->textureIndex_ > this->maxTextureIndex_) 83 this->textureIndex_ = 1; 82 return this->processCollision(otherObject, contactPoint, cs); 83 } 84 84 85 this->setMaterial(this->materialBase_); 85 void HoverGunProjectile::setCollisionShapeRadius(float radius) 86 { 87 if (collisionShape_ != nullptr && radius > 0) 88 { 89 collisionShape_->setRadius(radius); 90 } 86 91 } 87 92 } -
code/branches/Boxhead_FS19/src/modules/weapons/projectiles/HoverGunProjectile.h
r12274 r12284 21 21 * 22 22 * Author: 23 * Joel Smely23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * simonmie 26 26 * 27 27 */ … … 37 37 #include "weapons/WeaponsPrereqs.h" 38 38 39 #include <string>40 39 #include "tools/Timer.h" 41 #include "BillboardProjectile.h" 40 #include "worldentities/MovableEntity.h" 41 #include "objects/collisionshapes/SphereCollisionShape.h" 42 43 #include "BasicProjectile.h" 42 44 43 45 namespace orxonox … … 46 48 /** 47 49 @brief 48 The HoverGunProjectile is a projectile that is represented by a looped series of billboards.49 50 Represents all 'standard' projectiles. 51 50 52 @author 51 Joel Smely 53 Fabian 'x3n' Landau 54 @author 55 Simon Miescher 52 56 @ingroup WeaponsProjectiles 53 57 */ 54 class _WeaponsExport HoverGunProjectile : public BillboardProjectile58 class _WeaponsExport HoverGunProjectile : public MovableEntity, public BasicProjectile 55 59 { 56 60 public: 57 61 HoverGunProjectile(Context* context); 58 virtual ~HoverGunProjectile() {}62 virtual ~HoverGunProjectile(); 59 63 60 v irtual void setMaterial(const std::string& material) override;64 void setConfigValues(); 61 65 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; 66 68 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. 94 72 95 73 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. 103 76 }; 104 77 } 105 78 106 #endif /* _ HoverGunProjectile_H__ */79 #endif /* _Projectile_H__ */ -
code/branches/Boxhead_FS19/src/modules/weapons/weaponmodes/HoverGun.cc
r12273 r12284 21 21 * 22 22 * Author: 23 * Joel Smely23 * Hagen Seifert 24 24 * Co-authors: 25 25 * simonmie … … 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 38 #include "core/command/Executor.h" 39 40 #include "graphics/Model.h" 37 41 #include "weaponsystem/Weapon.h" 38 42 #include "weaponsystem/WeaponPack.h" 39 43 #include "weaponsystem/WeaponSystem.h" 44 #include "worldentities/WorldEntity.h" 40 45 #include "worldentities/pawns/Pawn.h" 41 46 42 47 #include "weapons/projectiles/HoverGunProjectile.h" 48 #include "weapons/MuzzleFlash.h" 43 49 44 50 namespace orxonox … … 50 56 RegisterObject(HoverGun); 51 57 52 this->reloadTime_ = 1.0f;53 this->damage_ = 0.0f; 58 this->reloadTime_ = 0.25f; 59 this->damage_ = 0.0f; //default 15 54 60 this->speed_ = 750.0f; 61 this->delay_ = 0.0f; 62 this->setMunitionName("LaserMunition"); 63 this->mesh_ = "laserbeam.mesh"; 55 64 56 this->setMunitionName("HoverMunition");57 this->setFireSound("sounds/Weapon_HoverGun.ogg");58 65 59 hudImageString_ = "Orxonox/WSHUD_WM_HoverGun"; 66 this->delayTimer_.setTimer(this->delay_, false, createExecutor(createFunctor(&HoverGun::shot, this))); 67 this->delayTimer_.stopTimer(); 68 69 this->setFireSound("sounds/Weapon_HsW01.ogg"); 70 this->setReloadSound("sounds/Reload_HsW01.ogg", 0.5); 71 72 hudImageString_ = "Orxonox/WSHUD_WM_HsW01"; 60 73 } 61 74 … … 64 77 } 65 78 79 void HoverGun::XMLPort(Element& xmlelement, XMLPort::Mode mode) 80 { 81 SUPER(HoverGun, XMLPort, xmlelement, mode); 82 83 XMLPortParam(HoverGun, "delay", setDelay, getDelay, xmlelement, mode); 84 XMLPortParam(HoverGun, "material", setMaterial, getMaterial, xmlelement, mode); 85 XMLPortParam(HoverGun, "projectileMesh", setMesh, getMesh, xmlelement, mode); 86 XMLPortParam(HoverGun, "sound", setSound, getSound, xmlelement, mode); 87 } 88 89 /** 90 @brief 91 Set the firing delay. 92 @param delay 93 The firing delay in seconds. 94 */ 95 void HoverGun::setDelay(float delay) 96 { 97 this->delay_ = delay; 98 this->delayTimer_.setInterval(this->delay_); 99 } 100 101 void HoverGun::fire() 102 { 103 this->delayTimer_.startTimer(); 104 } 105 66 106 /** 67 107 @brief 68 108 Fires the weapon. Creates a projectile and fires it. 69 109 */ 70 void HoverGun:: fire()110 void HoverGun::shot() 71 111 { 112 assert( this->getWeapon() && this->getWeapon()->getWeaponPack() && this->getWeapon()->getWeaponPack()->getWeaponSystem() && this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn() ); 113 114 // Create the projectile. 72 115 HoverGunProjectile* projectile = new HoverGunProjectile(this->getContext()); 73 projectile->setMaterial("Flares/HoverBall_"); 116 Model* model = new Model(projectile->getContext()); 117 model->setMeshSource(mesh_); 118 model->setCastShadows(false); 119 projectile->attach(model); 120 model->setScale(5); 74 121 75 122 this->computeMuzzleParameters(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getAimPosition()); … … 82 129 projectile->setShieldDamage(this->getShieldDamage()); 83 130 projectile->setHealthDamage(this->getHealthDamage()); 131 132 // Display the muzzle flash. 133 this->HoverGun::muzzleflash(); 134 } 135 136 /** 137 @brief 138 Displays the muzzle flash. 139 */ 140 void HoverGun::muzzleflash() 141 { 142 MuzzleFlash *muzzleFlash = new MuzzleFlash(this->getContext()); 143 this->getWeapon()->attach(muzzleFlash); 144 muzzleFlash->setPosition(this->getMuzzleOffset()); 145 muzzleFlash->setMaterial(this->material_); 84 146 } 85 147 } -
code/branches/Boxhead_FS19/src/modules/weapons/weaponmodes/HoverGun.h
r12273 r12284 21 21 * 22 22 * Author: 23 * Joel Smely23 * Hagen Seifert 24 24 * Co-authors: 25 25 * ... … … 36 36 37 37 #include "weapons/WeaponsPrereqs.h" 38 39 #include "tools/Timer.h" 38 40 #include "weaponsystem/WeaponMode.h" 39 41 … … 43 45 /** 44 46 @brief 45 A slow ball of lightning.47 Shoots laser beams. 46 48 @author 47 Joel Smely49 Hagen Seifert 48 50 @ingroup WeaponsWeaponModes 49 51 */ … … 55 57 56 58 virtual void fire() override; 59 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; 57 60 58 private: 61 protected: 62 /** 63 @brief Set the mesh. 64 @param mesh The mesh name. 65 */ 66 void setMesh(const std::string& mesh) 67 { this->mesh_ = mesh; } 68 69 /** 70 @brief Get the mesh. 71 @return Returns the mesh name. 72 */ 73 const std::string& getMesh() const 74 { return this->mesh_; } 75 76 /** 77 @brief Set the sound. 78 @param sound The Sound name. 79 */ 80 void setSound(const std::string& sound) 81 { this->sound_ = sound; } 82 83 /** 84 @brief Get the sound. 85 @return Returns the sound name. 86 */ 87 const std::string& getSound() const 88 { return this->sound_; } 89 90 /** 91 @brief Set the material. 92 @param material The material name. 93 */ 94 void setMaterial(const std::string& material) 95 { this->material_ = material; } 96 /** 97 @brief Get the material. 98 @return Returns the material name. 99 */ 100 const std::string& getMaterial() const 101 { return this->material_; } 102 103 void setDelay(float delay); 104 /** 105 @brief Get the firing delay. 106 @return Returns the firing delay in seconds. 107 */ 108 float getDelay() const 109 { return this->delay_; } 110 111 virtual void shot(); 112 void muzzleflash(); 113 114 std::string material_; //!< The material. 115 std::string mesh_; //!< The mesh. 116 std::string sound_; //!< The sound. 117 118 119 59 120 float speed_; //!< The speed of the fired projectile. 121 float delay_; //!< The firing delay. 122 Timer delayTimer_; //!< A timer to delay the firing. 60 123 }; 61 124 } -
code/branches/Boxhead_FS19/src/modules/weapons/weaponmodes/IceGun.cc
r11108 r12284 49 49 IceGun::IceGun(Context* context) : WeaponMode(context) 50 50 { 51 orxout() << "DEBUG Fire HoverGun"; 51 52 RegisterObject(IceGun); 52 53 -
code/branches/Boxhead_FS19/src/modules/weapons/weaponmodes/LightningGun.cc
r11108 r12284 48 48 LightningGun::LightningGun(Context* context) : WeaponMode(context) 49 49 { 50 orxout() << "DEBUG Fire HoverGun"; 50 51 RegisterObject(LightningGun); 51 52 … … 70 71 void LightningGun::fire() 71 72 { 73 72 74 LightningGunProjectile* projectile = new LightningGunProjectile(this->getContext()); 73 75 projectile->setMaterial("Flares/LightningBall_");
Note: See TracChangeset
for help on using the changeset viewer.