mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 11:34:46 +00:00
Bomb collisions should be good
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, float explosionRadius, int ownerID)
|
||||
BasicBombComponent::BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, unsigned ownerID)
|
||||
: WAL::Component(entity),
|
||||
damage(damage),
|
||||
explosionRadius(explosionRadius),
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace BBM
|
||||
{
|
||||
public:
|
||||
//! @brief The radius of the explosion.
|
||||
const float explosionRadius = 3;
|
||||
const int explosionRadius = 3;
|
||||
//! @brief The damage made by the explosion on an entity
|
||||
const int damage = 1;
|
||||
//! @brief The ID of the owner.
|
||||
int ownerID;
|
||||
unsigned ownerID;
|
||||
//! @brief Should collisions with the owner be disabled.²
|
||||
bool ignoreOwner = true;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace BBM
|
||||
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, int ownerID);
|
||||
explicit BasicBombComponent(WAL::Entity &entity, int damage, int explosionRadius, unsigned ownerID);
|
||||
|
||||
//! @brief A component can't be instantiated, it should be derived.
|
||||
BasicBombComponent(const BasicBombComponent &) = default;
|
||||
|
||||
@@ -7,12 +7,7 @@
|
||||
#include "System/Movable/MovableSystem.hpp"
|
||||
#include "System/Renderer/RenderSystem.hpp"
|
||||
#include <Model/Model.hpp>
|
||||
#include <Drawables/3D/Cube.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <Drawables/2D/Text.hpp>
|
||||
#include <Audio/Music.hpp>
|
||||
#include <Audio/Sound.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <TraceLog.hpp>
|
||||
#include "System/Keyboard/KeyboardSystem.hpp"
|
||||
#include "System/Controllable/ControllableSystem.hpp"
|
||||
@@ -22,7 +17,6 @@
|
||||
#include "System/Gamepad/GamepadSystem.hpp"
|
||||
#include <System/Collision/CollisionSystem.hpp>
|
||||
#include "Component/Button/ButtonComponent.hpp"
|
||||
#include <Component/Movable/MovableComponent.hpp>
|
||||
#include <Component/Collision/CollisionComponent.hpp>
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
@@ -35,7 +29,6 @@
|
||||
#include <System/Event/EventSystem.hpp>
|
||||
#include <System/Health/HealthSystem.hpp>
|
||||
#include <System/Animator/AnimatorSystem.hpp>
|
||||
#include <Component/Renderer/Drawable2DComponent.hpp>
|
||||
#include <Component/Animator/AnimatorComponent.hpp>
|
||||
#include <System/Levitate/LevitateSystem.hpp>
|
||||
#include <System/Bonus/PlayerBonusSystem.hpp>
|
||||
@@ -47,6 +40,7 @@
|
||||
#include "Map/Map.hpp"
|
||||
#include "System/MenuControllable/MenuControllableSystem.hpp"
|
||||
#include <Drawables/Texture.hpp>
|
||||
#include <System/Bomb/BombSystem.hpp>
|
||||
#include "Component/Music/MusicComponent.hpp"
|
||||
#include "Component/Sound/SoundComponent.hpp"
|
||||
#include "System/Sound/PlayerSoundManagerSystem.hpp"
|
||||
@@ -62,15 +56,10 @@ namespace BBM
|
||||
|
||||
void Runner::updateState(WAL::Wal &engine, GameState &state)
|
||||
{
|
||||
auto &view = engine.getScene()->view<ControllableComponent>();
|
||||
// You can change the scene here or update the game state based on entities values.
|
||||
|
||||
// If you want to keep a scene loaded but not running, store it in the state.loadedScenes.
|
||||
// If you don't need the scene anymore, remember to remove it from the loadedScene array.
|
||||
if (RAY::Window::getInstance().shouldClose())
|
||||
engine.shouldClose = true;
|
||||
if (gameState.currentScene == GameState::SceneID::GameScene) {
|
||||
for (auto &[_, component]: view) {
|
||||
for (auto &[_, component]: engine.getScene()->view<ControllableComponent>()) {
|
||||
if (component.pause) {
|
||||
gameState.nextScene = GameState::SceneID::PauseMenuScene;
|
||||
break;
|
||||
@@ -98,6 +87,7 @@ namespace BBM
|
||||
.addSystem<LevitateSystem>()
|
||||
.addSystem<PlayerBonusSystem>()
|
||||
.addSystem<MovableSystem>()
|
||||
.addSystem<BombSystem>()
|
||||
.addSystem<PlayerSoundManagerSystem>()
|
||||
.addSystem<MenuSoundManagerSystem>()
|
||||
.addSystem<MusicSystem>();
|
||||
|
||||
@@ -2,19 +2,28 @@
|
||||
// Created by Zoe Roux on 6/9/21.
|
||||
//
|
||||
|
||||
#include <Component/BombHolder/BombHolderComponent.hpp>
|
||||
#include "BombSystem.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
BombSystem::BombSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{
|
||||
{}
|
||||
|
||||
}
|
||||
|
||||
void BombSystem::onUpdate(WAL::ViewEntity<BasicBombComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
void BombSystem::onUpdate(WAL::ViewEntity<BasicBombComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
// if (entity.get<BasicBombComponent>().)
|
||||
// TODO set ignoreOwner to false once the player moved out of the block.
|
||||
auto &bomb = entity.get<BasicBombComponent>();
|
||||
if (!bomb.ignoreOwner)
|
||||
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 != ownerPos.position.round()) {
|
||||
bomb.ignoreOwner = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Bomb/BasicBombComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class BombSystem : public WAL::System<BasicBombComponent>
|
||||
class BombSystem : public WAL::System<BasicBombComponent, PositionComponent>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<BasicBombComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
void onUpdate(WAL::ViewEntity<BasicBombComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief Construct a new bomb system.
|
||||
explicit BombSystem(WAL::Wal &wal);
|
||||
|
||||
@@ -18,7 +18,7 @@ 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,
|
||||
@@ -62,7 +62,7 @@ namespace BBM
|
||||
_dispatchExplosion(position, wal, 3 + (explosionRadius - 3));
|
||||
}
|
||||
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, int id)
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id)
|
||||
{
|
||||
this->_wal.getScene()->scheduleNewEntity("Bomb")
|
||||
.addComponent<PositionComponent>(position.round())
|
||||
@@ -76,7 +76,8 @@ namespace BBM
|
||||
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>();
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace BBM
|
||||
{
|
||||
private:
|
||||
//! @brief Spawn a bomb at the specified position.
|
||||
void _spawnBomb(Vector3f position, BombHolderComponent &holder, int id);
|
||||
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);
|
||||
@@ -34,7 +34,8 @@ namespace BBM
|
||||
static std::chrono::nanoseconds explosionTimer;
|
||||
|
||||
//! @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