mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-07 05:40:40 +00:00
Add BombHolder Component
This commit is contained in:
39
sources/Component/BombHolder/BombHolderComponent.cpp
Normal file
39
sources/Component/BombHolder/BombHolderComponent.cpp
Normal 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;
|
||||
}
|
||||
}
|
||||
54
sources/Component/BombHolder/BombHolderComponent.hpp
Normal file
54
sources/Component/BombHolder/BombHolderComponent.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
@@ -39,6 +39,6 @@ namespace BBM
|
||||
|
||||
void HealthComponent::die(void)
|
||||
{
|
||||
this->_entity.setDisable(true)
|
||||
this->_entity.setDisable(true);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user