diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 4a582b26..42750d19 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -34,12 +34,12 @@ namespace BBM : System(wal) {} - void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, const Vector3f &posFrom) + void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections) { if (radiusToDo <= 0) return; std::cout << "exploding at " << position << std::endl; - wal.getSystem().dispatchEvent([position, radiusToDo, posFrom](WAL::Wal &wal) { + wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { if (auto *health = entity.tryGetComponent()) @@ -47,22 +47,17 @@ namespace BBM return; } } - const Vector3f expandVectors[] = { - {1, 0, 0}, - {-1, 0, 0}, - {0, 0, 1}, - {0, 0, -1}, - }; - - // should be true only at the first iteration - bool alwaysDispatch = position == posFrom; - - for (const auto &expandVector : expandVectors) { - Vector3f newPos = position + expandVector; - if (!alwaysDispatch && newPos == posFrom) { - continue; - } - _dispatchExplosion(newPos, wal, radiusToDo - 1, position); + if (expansionDirections & ExpansionDirection::FRONT) { + _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::FRONT); + } + if (expansionDirections & ExpansionDirection::BACK) { + _dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::BACK); + } + if (expansionDirections & ExpansionDirection::LEFT) { + _dispatchExplosion(position + Vector3f{0, 0, 1}, wal, radiusToDo - 1, ExpansionDirection::LEFT); + } + if (expansionDirections & ExpansionDirection::RIGHT) { + _dispatchExplosion(position + Vector3f{0, 0, -1}, wal, radiusToDo - 1, ExpansionDirection::RIGHT); } }); } @@ -72,7 +67,7 @@ namespace BBM bomb.scheduleDeletion(); auto position = bomb.getComponent().position.round(); auto explosionRadius = bomb.getComponent().explosionRadius; - _dispatchExplosion(position, wal, explosionRadius); + _dispatchExplosion(position, wal, 2); } void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 6c872ca8..e7245eae 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -14,6 +14,15 @@ namespace BBM { + enum ExpansionDirection { + UP = 1, + DOWN = 2, + LEFT = 4, + RIGHT = 8, + FRONT = 16, + BACK = 32 + }; + //! @brief The system that allow one to place bombs. class BombHolderSystem : public WAL::System { @@ -22,11 +31,19 @@ namespace BBM void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); //! @brief Spawn a bomb at the specified position. - static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, const Vector3f &posFrom); + static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections); //! @brief Wrapped call to specify default arg value inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) { - return _dispatchExplosion(position, wal, radiusToDo, position); + return _dispatchExplosion(position, + wal, + radiusToDo, + static_cast(ExpansionDirection::DOWN + | ExpansionDirection::UP + | ExpansionDirection::FRONT + | ExpansionDirection::BACK + | ExpansionDirection::LEFT + | ExpansionDirection::RIGHT)); }; //! @brief The method triggered when the bomb explode.