diff --git a/CMakeLists.txt b/CMakeLists.txt index fff0473e..bcaa0c02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ set(SOURCES sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.cpp -) + sources/System/Bomb/BombSystem.cpp sources/System/Bomb/BombSystem.hpp) add_executable(bomberman sources/main.cpp ${SOURCES} diff --git a/sources/Component/Bomb/BasicBombComponent.cpp b/sources/Component/Bomb/BasicBombComponent.cpp index 4c6f74af..dcf9627e 100644 --- a/sources/Component/Bomb/BasicBombComponent.cpp +++ b/sources/Component/Bomb/BasicBombComponent.cpp @@ -6,14 +6,15 @@ namespace BBM { - BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius) + BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius, int ownerID) : WAL::Component(entity), damage(damage), - explosionRadius(explosionRadius) + explosionRadius(explosionRadius), + ownerID(ownerID) {} WAL::Component *BasicBombComponent::clone(WAL::Entity &entity) const { - return new BasicBombComponent(entity, this->damage, this->explosionRadius); + return new BasicBombComponent(entity, this->damage, this->explosionRadius, this->ownerID); } } \ No newline at end of file diff --git a/sources/Component/Bomb/BasicBombComponent.hpp b/sources/Component/Bomb/BasicBombComponent.hpp index f9225a54..988304d2 100644 --- a/sources/Component/Bomb/BasicBombComponent.hpp +++ b/sources/Component/Bomb/BasicBombComponent.hpp @@ -19,12 +19,16 @@ namespace BBM const float explosionRadius = 3; //! @brief The damage made by the explosion on an entity const int damage = 1; + //! @brief The ID of the owner. + int ownerID; + //! @brief Should collisions with the owner be disabled.² + bool ignoreOwner = true; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; //! @brief A component can't be instantiated, it should be derived. - explicit BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius); + explicit BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius, int ownerID); //! @brief A component can't be instantiated, it should be derived. BasicBombComponent(const BasicBombComponent &) = default; diff --git a/sources/System/Bomb/BombSystem.cpp b/sources/System/Bomb/BombSystem.cpp new file mode 100644 index 00000000..c9b11fcc --- /dev/null +++ b/sources/System/Bomb/BombSystem.cpp @@ -0,0 +1,20 @@ +// +// Created by Zoe Roux on 6/9/21. +// + +#include "BombSystem.hpp" + +namespace BBM +{ + BombSystem::BombSystem(WAL::Wal &wal) + : System(wal) + { + + } + + void BombSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) + { +// if (entity.get().) + // TODO set ignoreOwner to false once the player moved out of the block. + } +} diff --git a/sources/System/Bomb/BombSystem.hpp b/sources/System/Bomb/BombSystem.hpp new file mode 100644 index 00000000..f84ee7b9 --- /dev/null +++ b/sources/System/Bomb/BombSystem.hpp @@ -0,0 +1,27 @@ +// +// Created by Zoe Roux on 6/9/21. +// + +#pragma once + +#include +#include "Component/Bomb/BasicBombComponent.hpp" + +namespace BBM +{ + class BombSystem : public WAL::System + { + public: + //! @inherit + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; + + //! @brief Construct a new bomb system. + explicit BombSystem(WAL::Wal &wal); + //! @brief A bomb system is copy constructable + BombSystem(const BombSystem &) = default; + //! @brief A default destructor + ~BombSystem() override = default; + //! @brief A bomb system can't be assigned. + BombSystem operator=(const BombSystem &) = delete; + }; +} diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index d862f5fe..eaf5ddf0 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -25,7 +25,7 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis) { auto &bombInfo = bomb.getComponent(); - if (bombInfo.skipOwner && bombInfo.owner == entity) + if (bombInfo.ignoreOwner && bombInfo.ownerID == entity.getUid()) return; return MapGenerator::wallCollide(entity, bomb, collidedAxis); } @@ -62,11 +62,11 @@ namespace BBM _dispatchExplosion(position, wal, 3 + (explosionRadius - 3)); } - void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder) + void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, int id) { this->_wal.scene->scheduleNewEntity("Bomb") .addComponent(position.round()) - .addComponent(holder.damage, holder.explosionRadius) + .addComponent(holder.damage, holder.explosionRadius, id) .addComponent(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) .addComponent(WAL::Callback(), &BombHolderSystem::_bombCollide, 0.25, .75) @@ -84,7 +84,7 @@ namespace BBM if (controllable.bomb && holder.bombCount > 0) { holder.bombCount--; - this->_spawnBomb(position.position, holder); + this->_spawnBomb(position.position, holder, entity->getUid()); } if (holder.bombCount < holder.maxBombCount) { holder.nextBombRefill -= dtime; diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 98449318..04ccc324 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -19,7 +19,7 @@ namespace BBM { private: //! @brief Spawn a bomb at the specified position. - void _spawnBomb(Vector3f position, BombHolderComponent &holder); + void _spawnBomb(Vector3f position, BombHolderComponent &holder, int id); //! @brief Spawn a bomb at the specified position. static void _dispatchExplosion(Vector3f position, WAL::Wal &, int count);