mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-02 02:05:25 +00:00
Starting a bomb system
This commit is contained in:
+1
-1
@@ -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}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<BasicBombComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
// if (entity.get<BasicBombComponent>().)
|
||||
// TODO set ignoreOwner to false once the player moved out of the block.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Zoe Roux on 6/9/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
#include "Component/Bomb/BasicBombComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class BombSystem : public WAL::System<BasicBombComponent>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<BasicBombComponent> &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;
|
||||
};
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace BBM
|
||||
CollisionComponent::CollidedAxis collidedAxis)
|
||||
{
|
||||
auto &bombInfo = bomb.getComponent<BasicBombComponent>();
|
||||
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<PositionComponent>(position.round())
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius)
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, id)
|
||||
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||
&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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user