mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-12 05:10:37 +00:00
explosion texture added (and merged with develop)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include <Component/Animation/AnimationsComponent.hpp>
|
||||
#include <Component/Bomb/BasicBombComponent.hpp>
|
||||
#include "Component/Timer/TimerComponent.hpp"
|
||||
#include "System/Event/EventSystem.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
@@ -18,7 +19,18 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
std::chrono::nanoseconds BombHolderSystem::explosionTimer = 3s;
|
||||
std::chrono::nanoseconds BombHolderSystem::explosionTimer = 2s;
|
||||
|
||||
void BombHolderSystem::_bombCollide(WAL::Entity &entity,
|
||||
const WAL::Entity &bomb,
|
||||
CollisionComponent::CollidedAxis collidedAxis)
|
||||
{
|
||||
auto &bombInfo = bomb.getComponent<BasicBombComponent>();
|
||||
if (bombInfo.ignoreOwner && bombInfo.ownerID == entity.getUid())
|
||||
return;
|
||||
return MapGenerator::wallCollided( entity, bomb, collidedAxis);
|
||||
}
|
||||
|
||||
|
||||
BombHolderSystem::BombHolderSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
@@ -28,15 +40,15 @@ namespace BBM
|
||||
{
|
||||
if (count <= 0)
|
||||
return;
|
||||
wal.scene->scheduleNewEntity("explosion")
|
||||
wal.getScene()->scheduleNewEntity("explosion")
|
||||
.addComponent<PositionComponent>(position)
|
||||
.addComponent<TimerComponent>(1s, [](WAL::Entity &explosion, WAL::Wal &wal) {
|
||||
explosion.scheduleDeletion();
|
||||
})
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb",
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb", false,
|
||||
std::make_pair(MAP_DIFFUSE, "assets/bombs/explosion/blast.png"));
|
||||
wal.getSystem<EventSystem>().dispatchEvent([position, count](WAL::Wal &wal) {
|
||||
for (auto &[entity, pos, _] : wal.scene->view<PositionComponent, TagComponent<Blowable>>()) {
|
||||
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<Blowable>>()) {
|
||||
if (pos.position.round() == position) {
|
||||
if (auto *health = entity.tryGetComponent<HealthComponent>())
|
||||
health->takeDmg(1);
|
||||
@@ -54,21 +66,26 @@ namespace BBM
|
||||
{
|
||||
bomb.scheduleDeletion();
|
||||
auto position = bomb.getComponent<PositionComponent>().position.round();
|
||||
_dispatchExplosion(position, wal, 3);
|
||||
auto explosionRadius = bomb.getComponent<BasicBombComponent>().explosionRadius;
|
||||
_dispatchExplosion(position, wal, 3 + (explosionRadius - 3));
|
||||
}
|
||||
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position)
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id)
|
||||
{
|
||||
this->_wal.scene->scheduleNewEntity("Bomb")
|
||||
this->_wal.getScene()->scheduleNewEntity("Bomb")
|
||||
.addComponent<PositionComponent>(position.round())
|
||||
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, id)
|
||||
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
|
||||
// .addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||
// &MapGenerator::wallCollide, 0.25, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/bomb.obj",
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||
&BombHolderSystem::_bombCollide, 0.25, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/bomb.obj", false,
|
||||
std::make_pair(MAP_DIFFUSE, "assets/bombs/bomb_normal.png"));
|
||||
holder.damage = 1;
|
||||
holder.explosionRadius = 3;
|
||||
}
|
||||
|
||||
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>();
|
||||
@@ -76,7 +93,7 @@ namespace BBM
|
||||
|
||||
if (controllable.bomb && holder.bombCount > 0) {
|
||||
holder.bombCount--;
|
||||
this->_spawnBomb(position.position);
|
||||
this->_spawnBomb(position.position, holder, entity->getUid());
|
||||
}
|
||||
if (holder.bombCount < holder.maxBombCount) {
|
||||
holder.nextBombRefill -= dtime;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <System/System.hpp>
|
||||
#include <Wal.hpp>
|
||||
#include <Component/Collision/CollisionComponent.hpp>
|
||||
#include "Models/Vector3.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||
@@ -18,21 +19,23 @@ namespace BBM
|
||||
{
|
||||
private:
|
||||
//! @brief Spawn a bomb at the specified position.
|
||||
void _spawnBomb(Vector3f position);
|
||||
void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id);
|
||||
|
||||
//! @brief Spawn a bomb at the specified position.
|
||||
static void _dispatchExplosion(Vector3f position, WAL::Wal &, int count);
|
||||
|
||||
//! @brief The method triggered when the bomb explode.
|
||||
static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &);
|
||||
|
||||
//! @brief The method called when a player collide with a bomb.
|
||||
static void _bombCollide(WAL::Entity &entity, const WAL::Entity &wall, BBM::CollisionComponent::CollidedAxis collidedAxis);
|
||||
public:
|
||||
//! @brief The explosion time of new bombs.
|
||||
static std::chrono::nanoseconds explosionTimer;
|
||||
//! @brief The radius of the explosion.
|
||||
static float explosionRadius;
|
||||
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<PositionComponent, BombHolderComponent, ControllableComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
void onUpdate(WAL::ViewEntity<PositionComponent, BombHolderComponent, ControllableComponent> &entity,
|
||||
std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit BombHolderSystem(WAL::Wal &wal);
|
||||
|
||||
Reference in New Issue
Block a user