Add BombHolder Component

This commit is contained in:
TrueBabyChaise
2021-05-20 16:55:28 +02:00
parent a8cd709874
commit da7694eb0b
4 changed files with 95 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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;
};
}

View File

@@ -39,6 +39,6 @@ namespace BBM
void HealthComponent::die(void)
{
this->_entity.setDisable(true)
this->_entity.setDisable(true);
}
}

View File

@@ -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;
};
}