From da7694eb0b52c373bd493ccfc5dd0756a779bc69 Mon Sep 17 00:00:00 2001 From: TrueBabyChaise Date: Thu, 20 May 2021 16:55:28 +0200 Subject: [PATCH] Add BombHolder Component --- .../BombHolder/BombHolderComponent.cpp | 39 ++++++++++++++ .../BombHolder/BombHolderComponent.hpp | 54 +++++++++++++++++++ sources/Component/Health/HealthComponent.cpp | 2 +- sources/Component/Health/HealthComponent.hpp | 4 +- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 sources/Component/BombHolder/BombHolderComponent.cpp create mode 100644 sources/Component/BombHolder/BombHolderComponent.hpp diff --git a/sources/Component/BombHolder/BombHolderComponent.cpp b/sources/Component/BombHolder/BombHolderComponent.cpp new file mode 100644 index 00000000..031dab8b --- /dev/null +++ b/sources/Component/BombHolder/BombHolderComponent.cpp @@ -0,0 +1,39 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// Edited by Louis Auzuret on 2021-05-20. +// + +#include "BombHolderComponent.hpp" + +namespace BBM +{ + BombHolderComponent::BombHolderComponent(WAL::Entity &entity) + : WAL::Component(entity), + _bombCount() + {} + + BombHolderComponent::BombHolderComponent(WAL::Entity &entity, unsigned int maxBombCount) + : WAL::Component(entity), + _bombCount(), + _maxBombCount(maxBombCount) + {} + + WAL::Component *BombHolderComponent::clone(WAL::Entity &entity) const + { + return new BombHolderComponent(entity); + } + + void BombHolderComponent::addBomb(unsigned int bombCount) + { + this->_bombCount += bombCount; + } + + void BombHolderComponent::removeBomb(unsigned int damage) + { + if (damage >= this->_bombCount) { + this->_bombCount = 0; + } else + this->_bombCount -= damage; + } +} \ No newline at end of file diff --git a/sources/Component/BombHolder/BombHolderComponent.hpp b/sources/Component/BombHolder/BombHolderComponent.hpp new file mode 100644 index 00000000..97e236d6 --- /dev/null +++ b/sources/Component/BombHolder/BombHolderComponent.hpp @@ -0,0 +1,54 @@ +// +// Created by Tom Augier on 2021-05-20. +// Edited by Benjamin Henry on 2021-05-20. +// Edited by Louis Auzuret on 2021-05-20. +// + +#pragma once + +#include "lib/wal/sources/Component/Component.hpp" +#include "lib/wal/sources/Entity/Entity.hpp" + +namespace BBM +{ + class BombHolderComponent : public WAL::Component + { + + private: + //! @brief bomb count of an entity + unsigned int _bombCount; + //! @brief max bomb count of an entity + unsigned int _maxBombCount; + + public: + //! @brief add bomb to the entity + void addBomb(unsigned int bombCount); + + //! @brief add bomb bax of the entity + void addMaxBombCount(unsigned int maxBombCount); + + //! @brief reduce bomb max of the entity + void removeMaxBombCount(unsigned int bombCount); + + //! @brief reduce bomb + void removeBomb(unsigned int bombCount); + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A component can't be instantiated, it should be derived. + explicit BombHolderComponent(WAL::Entity &entity); + + //! @brief Constructor + BombHolderComponent(WAL::Entity &entity, unsigned int maxBombCount); + + //! @brief A component can't be instantiated, it should be derived. + BombHolderComponent(const BombHolderComponent &) = default; + + //! @brief default destructor + ~BombHolderComponent() override = default; + + //! @brief A component can't be assigned + BombHolderComponent &operator=(const BombHolderComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.cpp b/sources/Component/Health/HealthComponent.cpp index 28e93b1a..a129a24e 100644 --- a/sources/Component/Health/HealthComponent.cpp +++ b/sources/Component/Health/HealthComponent.cpp @@ -39,6 +39,6 @@ namespace BBM void HealthComponent::die(void) { - this->_entity.setDisable(true) + this->_entity.setDisable(true); } } \ No newline at end of file diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index 131fc33d..ecc67b12 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -25,7 +25,7 @@ namespace BBM //! @brief reduce health void takeDmg(unsigned int damage); - //! @brief health to 0 + //! @brief disable the entity void die(void); //! @inherit @@ -45,7 +45,5 @@ namespace BBM //! @brief A component can't be assigned HealthComponent &operator=(const HealthComponent &) = delete; - - friend class HealthSystem; }; } \ No newline at end of file