mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-29 17:02:11 +00:00
testing bombs
This commit is contained in:
@@ -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<EventSystem>().dispatchEvent([position, radiusToDo, posFrom](WAL::Wal &wal) {
|
||||
wal.getSystem<EventSystem>().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) {
|
||||
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<Blowable>>()) {
|
||||
if (pos.position.round() == position) {
|
||||
if (auto *health = entity.tryGetComponent<HealthComponent>())
|
||||
@@ -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<PositionComponent>().position.round();
|
||||
auto explosionRadius = bomb.getComponent<BasicBombComponent>().explosionRadius;
|
||||
_dispatchExplosion(position, wal, explosionRadius);
|
||||
_dispatchExplosion(position, wal, 2);
|
||||
}
|
||||
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id)
|
||||
|
||||
@@ -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<PositionComponent, BombHolderComponent, ControllableComponent>
|
||||
{
|
||||
@@ -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>(ExpansionDirection::DOWN
|
||||
| ExpansionDirection::UP
|
||||
| ExpansionDirection::FRONT
|
||||
| ExpansionDirection::BACK
|
||||
| ExpansionDirection::LEFT
|
||||
| ExpansionDirection::RIGHT));
|
||||
};
|
||||
|
||||
//! @brief The method triggered when the bomb explode.
|
||||
|
||||
Reference in New Issue
Block a user