mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-27 16:22:09 +00:00
@@ -4,17 +4,19 @@
|
||||
|
||||
#include "BasicBombComponent.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, unsigned ownerID)
|
||||
: WAL::Component(entity),
|
||||
damage(damage),
|
||||
explosionRadius(explosionRadius),
|
||||
ownerID(ownerID)
|
||||
BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, std::vector<unsigned> ignored)
|
||||
: WAL::Component(entity),
|
||||
damage(damage),
|
||||
explosionRadius(explosionRadius),
|
||||
ignoredEntities(std::move(ignored))
|
||||
{}
|
||||
|
||||
WAL::Component *BasicBombComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new BasicBombComponent(entity, this->damage, this->explosionRadius, this->ownerID);
|
||||
return new BasicBombComponent(entity, this->damage, this->explosionRadius, this->ignoredEntities);
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,14 @@ namespace BBM
|
||||
const int explosionRadius = 3;
|
||||
//! @brief The damage made by the explosion on an entity
|
||||
const int damage = 1;
|
||||
//! @brief The ID of the owner.
|
||||
unsigned ownerID;
|
||||
//! @brief Should collisions with the owner be disabled.²
|
||||
bool ignoreOwner = true;
|
||||
//! @brief The list of IDs of ignored entities.
|
||||
std::vector<unsigned> ignoredEntities;
|
||||
|
||||
//! @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, int explosionRadius, unsigned ownerID);
|
||||
explicit BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, std::vector<unsigned> ignored);
|
||||
|
||||
//! @brief A component can't be instantiated, it should be derived.
|
||||
BasicBombComponent(const BasicBombComponent &) = default;
|
||||
|
||||
@@ -14,15 +14,16 @@ namespace BBM
|
||||
void BombSystem::onUpdate(WAL::ViewEntity<BasicBombComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &bomb = entity.get<BasicBombComponent>();
|
||||
if (!bomb.ignoreOwner)
|
||||
|
||||
if (bomb.ignoredEntities.empty())
|
||||
return;
|
||||
|
||||
auto &pos = entity.get<PositionComponent>();
|
||||
for (auto &[owner, ownerPos, _] : this->_wal.getScene()->view<PositionComponent, BombHolderComponent>()) {
|
||||
if (owner.getUid() != bomb.ownerID)
|
||||
continue;
|
||||
if (pos.position.distance(ownerPos.position) >= 1.1) {
|
||||
bomb.ignoreOwner = false;
|
||||
return;
|
||||
bomb.ignoredEntities.erase(
|
||||
std::remove(bomb.ignoredEntities.begin(), bomb.ignoredEntities.end(), owner.getUid()),
|
||||
bomb.ignoredEntities.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Created by Zoe Roux on 5/31/21.
|
||||
//
|
||||
|
||||
#include <Component/Animation/AnimationsComponent.hpp>
|
||||
#include <Component/Bomb/BasicBombComponent.hpp>
|
||||
#include "Component/Timer/TimerComponent.hpp"
|
||||
#include "System/Event/EventSystem.hpp"
|
||||
@@ -31,7 +30,8 @@ namespace BBM
|
||||
CollisionComponent::CollidedAxis collidedAxis)
|
||||
{
|
||||
auto &bombInfo = bomb.getComponent<BasicBombComponent>();
|
||||
if (bombInfo.ignoreOwner && bombInfo.ownerID == entity.getUid())
|
||||
auto found = std::find(bombInfo.ignoredEntities.begin(), bombInfo.ignoredEntities.end(), entity.getUid());
|
||||
if (found != bombInfo.ignoredEntities.end())
|
||||
return;
|
||||
return MapGenerator::wallCollided(entity, bomb, collidedAxis);
|
||||
}
|
||||
@@ -115,10 +115,17 @@ namespace BBM
|
||||
_dispatchExplosion(position, wal, explosionRadius);
|
||||
}
|
||||
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id)
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder)
|
||||
{
|
||||
std::vector<unsigned> overlapping;
|
||||
|
||||
for (auto &[entity, pos, _] : this->_wal.getScene()->view<PositionComponent, BombHolderComponent>()) {
|
||||
if (position.distance(pos.position) <= 1.1)
|
||||
overlapping.emplace_back(entity.getUid());
|
||||
}
|
||||
|
||||
this->_wal.getScene()->scheduleNewEntity("Bomb")
|
||||
.addComponent<PositionComponent>(position.round())
|
||||
.addComponent<PositionComponent>(position)
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) {
|
||||
// the bomb explode when hit
|
||||
entity.scheduleDeletion();
|
||||
@@ -154,7 +161,7 @@ namespace BBM
|
||||
})
|
||||
.addComponent<WhiteShaderComponent>()
|
||||
.addComponent<TagComponent<BlowablePass>>()
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, id)
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, overlapping)
|
||||
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
|
||||
.addComponent<CollisionComponent>(
|
||||
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||
@@ -166,18 +173,13 @@ namespace BBM
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
BombHolderSystem::onUpdate(WAL::ViewEntity<PositionComponent, BombHolderComponent, ControllableComponent> &entity,
|
||||
std::chrono::nanoseconds dtime)
|
||||
void BombHolderSystem::onUpdate(WAL::ViewEntity<PositionComponent, BombHolderComponent, ControllableComponent> &entity,
|
||||
std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &holder = entity.get<BombHolderComponent>();
|
||||
auto &position = entity.get<PositionComponent>();
|
||||
auto &controllable = entity.get<ControllableComponent>();
|
||||
|
||||
if (controllable.bomb && holder.bombCount > 0) {
|
||||
holder.bombCount--;
|
||||
this->_spawnBomb(position.position, holder, entity->getUid());
|
||||
}
|
||||
if (holder.bombCount < holder.maxBombCount) {
|
||||
holder.nextBombRefill -= dtime;
|
||||
if (holder.nextBombRefill <= 0ns) {
|
||||
@@ -185,5 +187,14 @@ namespace BBM
|
||||
holder.bombCount++;
|
||||
}
|
||||
}
|
||||
if (controllable.bomb && holder.bombCount > 0) {
|
||||
auto spawnPos = position.position.round();
|
||||
for (auto &[entity, pos, _] : this->_wal.getScene()->view<PositionComponent, BasicBombComponent>()) {
|
||||
if (pos.position == spawnPos)
|
||||
return;
|
||||
}
|
||||
holder.bombCount--;
|
||||
this->_spawnBomb(spawnPos, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace BBM
|
||||
{
|
||||
private:
|
||||
//! @brief Spawn a bomb at the specified position.
|
||||
void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id);
|
||||
void _spawnBomb(Vector3f position, BombHolderComponent &holder);
|
||||
|
||||
//! @brief Spawn a bomb at the specified position.
|
||||
static void _dispatchExplosion(const Vector3f &position,
|
||||
|
||||
Reference in New Issue
Block a user