mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 19:40:48 +00:00
Merge branch 'develop' of github.com:AnonymusRaccoon/Bomberman into lobby
This commit is contained in:
@@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D
|
||||
{
|
||||
DrawCubeV(this->_position, this->_dimensions, this->_color);
|
||||
}
|
||||
|
||||
void Cube::drawWiresOn(RAY::Window &)
|
||||
{
|
||||
DrawCubeWiresV(this->_position, this->_dimensions, this->_debugColor);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,9 @@ namespace RAY::Drawables::Drawables3D {
|
||||
|
||||
//! @brief Draw circle on window
|
||||
void drawOn(RAY::Window &) override;
|
||||
|
||||
//! @brief Draw cube's wires on window
|
||||
void drawWiresOn(RAY::Window &) override;
|
||||
private:
|
||||
//! @brief Dimensions of the cube
|
||||
Vector3 _dimensions;
|
||||
|
||||
@@ -52,4 +52,9 @@ namespace RAY::Drawables::Drawables3D
|
||||
{
|
||||
DrawCylinder(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color);
|
||||
}
|
||||
|
||||
void Cylinder::drawWiresOn(RAY::Window &)
|
||||
{
|
||||
DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_debugColor);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,8 @@ namespace RAY::Drawables::Drawables3D {
|
||||
//! @brief Draw point on window
|
||||
void drawOn(RAY::Window &) override;
|
||||
|
||||
//! @brief Draw cylinder's wires on window
|
||||
void drawWiresOn(RAY::Window &) override;
|
||||
private:
|
||||
//! @brief Radius of the cylinder
|
||||
float _topRadius;
|
||||
|
||||
@@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D
|
||||
{
|
||||
DrawSphere(this->_position, this->_radius, this->_color);
|
||||
}
|
||||
|
||||
void Sphere::drawWiresOn(RAY::Window &)
|
||||
{
|
||||
DrawSphereWires(this->_position, this->_radius, 10, 10, this->_debugColor);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,9 @@ namespace RAY::Drawables::Drawables3D {
|
||||
//! @brief Draw point on window
|
||||
void drawOn(RAY::Window &) override;
|
||||
|
||||
//! @brief Draw sphere's wires on window
|
||||
void drawWiresOn(RAY::Window &) override;
|
||||
|
||||
private:
|
||||
//! @brief Radius of the sphere
|
||||
int _radius;
|
||||
|
||||
@@ -36,4 +36,18 @@ namespace RAY::Drawables
|
||||
this->_position = position;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ADrawable3D::drawWiresOn(RAY::Window &)
|
||||
{}
|
||||
|
||||
const RAY::Color &ADrawable3D::getDebugColor(void) const
|
||||
{
|
||||
return this->_debugColor;
|
||||
}
|
||||
|
||||
ADrawable3D &ADrawable3D::setDebugColor(const Color &debugColor)
|
||||
{
|
||||
this->_debugColor = debugColor;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,21 @@ namespace RAY::Drawables {
|
||||
//! @brief Draw drawble on window
|
||||
void drawOn(RAY::Window &) override = 0;
|
||||
|
||||
//! @brief Draw drawble's wires on window
|
||||
virtual void drawWiresOn(RAY::Window &);
|
||||
|
||||
//! @return the color of the ADrawable
|
||||
const RAY::Color &getColor(void) const;
|
||||
|
||||
|
||||
//! @brief set color
|
||||
ADrawable3D &setColor(const RAY::Color &color);
|
||||
|
||||
//! @return the debug color of the ADrawable
|
||||
const RAY::Color &getDebugColor(void) const;
|
||||
|
||||
//! @brief set the debug color
|
||||
ADrawable3D &setDebugColor(const RAY::Color &debugColor);
|
||||
|
||||
//! @return the position of the ADrawable
|
||||
virtual const RAY::Vector3 &getPosition(void) const;
|
||||
|
||||
@@ -49,6 +58,9 @@ namespace RAY::Drawables {
|
||||
//! @brief Color of the ADrawable
|
||||
Color _color;
|
||||
|
||||
//! @brief Color of the ADrawable's Debug
|
||||
Color _debugColor = GREEN;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -114,6 +114,20 @@ namespace RAY::Drawables::Drawables3D
|
||||
this->_color);
|
||||
}
|
||||
|
||||
void Model::drawWiresOn(RAY::Window &)
|
||||
{
|
||||
if (this->_model->meshCount) {
|
||||
::BoundingBox box = GetMeshBoundingBox(*this->_model->meshes);
|
||||
box.min.x += this->_position.x;
|
||||
box.min.y += this->_position.y;
|
||||
box.min.z += this->_position.z;
|
||||
box.max.x += this->_position.x;
|
||||
box.max.y += this->_position.y;
|
||||
box.max.z += this->_position.z;
|
||||
DrawBoundingBox(box, this->_debugColor);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::setShader(const RAY::Shader &shader)
|
||||
{
|
||||
this->_originalShader = this->_model->materials[0].shader;
|
||||
|
||||
@@ -87,6 +87,9 @@ namespace RAY::Drawables::Drawables3D {
|
||||
|
||||
void drawOn(RAY::Window &) override;
|
||||
|
||||
//! @brief Draw model's wires on window
|
||||
void drawWiresOn(RAY::Window &) override;
|
||||
|
||||
private:
|
||||
//! @brief Raw data from raylib
|
||||
std::shared_ptr<::Model> _model;
|
||||
|
||||
+4
-1
@@ -9,6 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <Items/Bonus.hpp>
|
||||
#include <Component/Levitate/LevitateComponent.hpp>
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include <Component/Timer/TimerComponent.hpp>
|
||||
#include <Component/Tag/TagComponent.hpp>
|
||||
|
||||
@@ -53,6 +54,8 @@ namespace BBM
|
||||
return;
|
||||
wal.getScene()->scheduleNewEntity("Bonus")
|
||||
.addComponent<PositionComponent>(position)
|
||||
.addComponent<TagComponent<Blowable>>()
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) {
|
||||
entity.scheduleDeletion();
|
||||
})
|
||||
@@ -165,7 +168,7 @@ namespace BBM
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER)
|
||||
scene->addEntity("Unbreakable Wall")
|
||||
scene->addEntity("Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(i, -1, j))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, false,
|
||||
std::make_pair(MAP_DIFFUSE, floorPng));
|
||||
|
||||
@@ -173,6 +173,11 @@ namespace BBM
|
||||
return Vector3<T>(std::round(this->x), std::round(this->y), std::round(this->z));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isNull() const
|
||||
{
|
||||
return this->x == 0 && this->y == 0 && this->z == 0;
|
||||
}
|
||||
|
||||
operator RAY::Vector3() const requires(std::is_same_v<T, float>)
|
||||
{
|
||||
return RAY::Vector3(this->x, this->y, this->z);
|
||||
|
||||
@@ -22,23 +22,25 @@ namespace BBM
|
||||
std::chrono::nanoseconds BombHolderSystem::explosionTimer = 2s;
|
||||
|
||||
void BombHolderSystem::_bombCollide(WAL::Entity &entity,
|
||||
const WAL::Entity &bomb,
|
||||
CollisionComponent::CollidedAxis collidedAxis)
|
||||
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);
|
||||
return MapGenerator::wallCollided(entity, bomb, collidedAxis);
|
||||
}
|
||||
|
||||
|
||||
BombHolderSystem::BombHolderSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{}
|
||||
|
||||
void BombHolderSystem::_dispatchExplosion(Vector3f position, WAL::Wal &wal, int count)
|
||||
void BombHolderSystem::_dispatchExplosion(const Vector3f &position,
|
||||
WAL::Wal &wal,
|
||||
int size,
|
||||
ExpansionDirection expansionDirections)
|
||||
{
|
||||
if (count <= 0)
|
||||
if (size <= 0)
|
||||
return;
|
||||
wal.getScene()->scheduleNewEntity("explosion")
|
||||
.addComponent<PositionComponent>(position)
|
||||
@@ -46,8 +48,11 @@ namespace BBM
|
||||
explosion.scheduleDeletion();
|
||||
})
|
||||
.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) {
|
||||
std::make_pair(
|
||||
MAP_DIFFUSE,
|
||||
"assets/bombs/explosion/blast.png"
|
||||
));
|
||||
wal.getSystem<EventSystem>().dispatchEvent([position, size, expansionDirections](WAL::Wal &wal) {
|
||||
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<Blowable>>()) {
|
||||
if (pos.position.round() == position) {
|
||||
if (auto *health = entity.tryGetComponent<HealthComponent>())
|
||||
@@ -55,10 +60,18 @@ namespace BBM
|
||||
return;
|
||||
}
|
||||
}
|
||||
_dispatchExplosion(position + Vector3f(1, 0, 0), wal, count - 1);
|
||||
_dispatchExplosion(position + Vector3f(-1, 0, 0), wal, count - 1);
|
||||
_dispatchExplosion(position + Vector3f(0, 0, 1), wal, count - 1);
|
||||
_dispatchExplosion(position + Vector3f(0, 0, -1), wal, count - 1);
|
||||
if (expansionDirections & ExpansionDirection::FRONT) {
|
||||
_dispatchExplosion(position + Vector3f{1, 0, 0}, wal, size - 1, ExpansionDirection::FRONT);
|
||||
}
|
||||
if (expansionDirections & ExpansionDirection::BACK) {
|
||||
_dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, size - 1, ExpansionDirection::BACK);
|
||||
}
|
||||
if (expansionDirections & ExpansionDirection::LEFT) {
|
||||
_dispatchExplosion(position + Vector3f{0, 0, 1}, wal, size - 1, ExpansionDirection::LEFT);
|
||||
}
|
||||
if (expansionDirections & ExpansionDirection::RIGHT) {
|
||||
_dispatchExplosion(position + Vector3f{0, 0, -1}, wal, size - 1, ExpansionDirection::RIGHT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,7 +80,7 @@ namespace BBM
|
||||
bomb.scheduleDeletion();
|
||||
auto position = bomb.getComponent<PositionComponent>().position.round();
|
||||
auto explosionRadius = bomb.getComponent<BasicBombComponent>().explosionRadius;
|
||||
_dispatchExplosion(position, wal, 3 + (explosionRadius - 3));
|
||||
_dispatchExplosion(position, wal, explosionRadius);
|
||||
}
|
||||
|
||||
void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id)
|
||||
@@ -76,16 +89,21 @@ namespace BBM
|
||||
.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>(),
|
||||
&BombHolderSystem::_bombCollide, 0.25, .75)
|
||||
.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"));
|
||||
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>();
|
||||
|
||||
@@ -14,6 +14,22 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
enum ExpansionDirection
|
||||
{
|
||||
UP = 1,
|
||||
DOWN = 2,
|
||||
LEFT = 4,
|
||||
RIGHT = 8,
|
||||
FRONT = 16,
|
||||
BACK = 32
|
||||
};
|
||||
|
||||
//! @brief Ta avoid explicit casting
|
||||
inline ExpansionDirection operator|(ExpansionDirection a, ExpansionDirection b)
|
||||
{
|
||||
return static_cast<ExpansionDirection>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
//! @brief The system that allow one to place bombs.
|
||||
class BombHolderSystem : public WAL::System<PositionComponent, BombHolderComponent, ControllableComponent>
|
||||
{
|
||||
@@ -22,13 +38,23 @@ namespace BBM
|
||||
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);
|
||||
static void _dispatchExplosion(const Vector3f &position,
|
||||
WAL::Wal &wal,
|
||||
int size,
|
||||
ExpansionDirection expansionDirections = ExpansionDirection::DOWN
|
||||
| ExpansionDirection::UP
|
||||
| ExpansionDirection::FRONT
|
||||
| ExpansionDirection::BACK
|
||||
| ExpansionDirection::LEFT
|
||||
| ExpansionDirection::RIGHT);
|
||||
|
||||
//! @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);
|
||||
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;
|
||||
@@ -39,10 +65,13 @@ namespace BBM
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit BombHolderSystem(WAL::Wal &wal);
|
||||
|
||||
//! @brief A bomb holder system is copy constructable
|
||||
BombHolderSystem(const BombHolderSystem &) = default;
|
||||
|
||||
//! @brief A default destructor
|
||||
~BombHolderSystem() override = default;
|
||||
|
||||
//! @brief A bomb holder system is not assignable.
|
||||
BombHolderSystem &operator=(const BombHolderSystem &) = delete;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BBM
|
||||
return (overlapX && overlapY && overlapZ);
|
||||
}
|
||||
|
||||
void CollisionSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent> &entity)
|
||||
void CollisionSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent, MovableComponent> &entity)
|
||||
{
|
||||
unsigned int entityUid = entity->getUid();
|
||||
auto &posA = entity.get<PositionComponent>();
|
||||
@@ -33,8 +33,10 @@ namespace BBM
|
||||
Vector3f pointAy = pointA;
|
||||
Vector3f pointAz = pointA;
|
||||
|
||||
if (auto *movable = entity->tryGetComponent<MovableComponent>()) {
|
||||
auto vel = movable->getVelocity();
|
||||
auto &movable = entity.get<MovableComponent>();
|
||||
const auto &vel = movable.getVelocity();
|
||||
|
||||
if (!vel.isNull()) {
|
||||
pointAx.x += vel.x;
|
||||
pointAy.y += vel.y;
|
||||
pointAz.z += vel.z;
|
||||
@@ -43,13 +45,21 @@ namespace BBM
|
||||
Vector3f minAx = Vector3f::min(pointAx, pointAx + colA.bound);
|
||||
Vector3f maxAx = Vector3f::max(pointAx, pointAx + colA.bound);
|
||||
|
||||
Vector3f minAy = Vector3f::min(pointAy, pointAy + colA.bound);
|
||||
Vector3f maxAy = Vector3f::max(pointAy, pointAy + colA.bound);
|
||||
Vector3f minAy;
|
||||
Vector3f maxAy;
|
||||
|
||||
Vector3f minAz = Vector3f::min(pointAz, pointAz + colA.bound);
|
||||
Vector3f maxAz = Vector3f::max(pointAz, pointAz + colA.bound);
|
||||
Vector3f minAz;
|
||||
Vector3f maxAz;
|
||||
|
||||
for (auto &[other, posB, colB] : this->getView()) {
|
||||
if (!vel.isNull()) {
|
||||
minAy = Vector3f::min(pointAy, pointAy + colA.bound);
|
||||
maxAy = Vector3f::max(pointAy, pointAy + colA.bound);
|
||||
|
||||
minAz = Vector3f::min(pointAz, pointAz + colA.bound);
|
||||
maxAz = Vector3f::max(pointAz, pointAz + colA.bound);
|
||||
}
|
||||
|
||||
for (auto &[other, posB, colB] : this->_wal.getScene()->view<PositionComponent, CollisionComponent>()) {
|
||||
if (other.getUid() == entityUid)
|
||||
continue;
|
||||
|
||||
@@ -60,13 +70,15 @@ namespace BBM
|
||||
Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound);
|
||||
|
||||
if (boxesCollide(minAx, maxAx, minB, maxB)) {
|
||||
collidedAxis += CollisionComponent::CollidedAxis::X;
|
||||
collidedAxis += vel.isNull() ? 7 : CollisionComponent::CollidedAxis::X;
|
||||
}
|
||||
if (boxesCollide(minAy, maxAy, minB, maxB)) {
|
||||
collidedAxis += CollisionComponent::CollidedAxis::Y;
|
||||
}
|
||||
if (boxesCollide(minAz, maxAz, minB, maxB)) {
|
||||
collidedAxis += CollisionComponent::CollidedAxis::Z;
|
||||
if (!vel.isNull()) {
|
||||
if (boxesCollide(minAy, maxAy, minB, maxB)) {
|
||||
collidedAxis += CollisionComponent::CollidedAxis::Y;
|
||||
}
|
||||
if (boxesCollide(minAz, maxAz, minB, maxB)) {
|
||||
collidedAxis += CollisionComponent::CollidedAxis::Z;
|
||||
}
|
||||
}
|
||||
if (collidedAxis) {
|
||||
colA.onCollide(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
|
||||
|
||||
@@ -10,16 +10,17 @@
|
||||
#include "System/System.hpp"
|
||||
#include "Models/Vector3.hpp"
|
||||
#include "Component/Collision/CollisionComponent.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle collisions.
|
||||
class CollisionSystem : public WAL::System<PositionComponent, CollisionComponent>
|
||||
class CollisionSystem : public WAL::System<PositionComponent, CollisionComponent, MovableComponent>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent> &entity) override;
|
||||
void onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent, MovableComponent> &entity) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
explicit CollisionSystem(WAL::Wal &wal);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <Model/Model.hpp>
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
#include "Component/Shaders/ShaderComponent.hpp"
|
||||
|
||||
|
||||
#include <Drawables/3D/Cube.hpp>
|
||||
#include "Models/Vector3.hpp"
|
||||
#include "Component/Collision/CollisionComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
@@ -26,6 +26,20 @@ namespace BBM
|
||||
this->_window.setFPS(this->FPS);
|
||||
}
|
||||
|
||||
void RenderSystem::drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const
|
||||
{
|
||||
auto *dimsComponent = entity.tryGetComponent<CollisionComponent>();
|
||||
|
||||
//draws hitbox
|
||||
if (dimsComponent) {
|
||||
RAY::Drawables::Drawables3D::Cube boundingBox(posComponent.position, dimsComponent->bound, WHITE);
|
||||
boundingBox.setDebugColor(RED);
|
||||
boundingBox.drawWiresOn(this->_window);
|
||||
}
|
||||
//draws models contours
|
||||
drawable.drawable->drawWiresOn(this->_window);
|
||||
}
|
||||
|
||||
void RenderSystem::onSelfUpdate()
|
||||
{
|
||||
this->_camera.update();
|
||||
@@ -42,6 +56,8 @@ namespace BBM
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
if (modelShader)
|
||||
modelShader->model->resetShader();
|
||||
if (this->_debugMode)
|
||||
this->drawBoundingBox(entity, pos, drawable);
|
||||
}
|
||||
this->_window.unuseCamera();
|
||||
|
||||
@@ -59,7 +75,7 @@ namespace BBM
|
||||
}
|
||||
}
|
||||
if (this->_debugMode)
|
||||
this->_window.drawFPS(Vector2f());
|
||||
this->_window.drawFPS(Vector2f(10, 10));
|
||||
this->_window.endDrawing();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "System/System.hpp"
|
||||
#include "Camera/Camera2D.hpp"
|
||||
#include "Window.hpp"
|
||||
@@ -39,6 +40,9 @@ namespace BBM
|
||||
//! @param debug true if debug mode should be enabled
|
||||
void setDebug(bool debug);
|
||||
|
||||
//! @param entity entity to draw bounding box of
|
||||
void drawBoundingBox(const WAL::Entity &entity, const PositionComponent &posComponent, const Drawable3DComponent &drawable) const;
|
||||
|
||||
//! @brief ctor
|
||||
RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode = false);
|
||||
//! @brief Default copy ctor
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
using namespace WAL;
|
||||
using namespace BBM;
|
||||
|
||||
// WARN THE COLLISION SYSTEM IS ONLY CHECKING/LOOPING ON MOVABLE ENTITIES
|
||||
|
||||
|
||||
TEST_CASE("Collision test", "[Component][System]")
|
||||
{
|
||||
@@ -25,6 +27,7 @@ TEST_CASE("Collision test", "[Component][System]")
|
||||
wal.changeScene(std::make_shared<Scene>());
|
||||
wal.getScene()->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int _) {
|
||||
try {
|
||||
auto &pos = actual.getComponent<PositionComponent>();
|
||||
@@ -118,6 +121,7 @@ TEST_CASE("Collision test callbacks calls", "[Component][System]")
|
||||
|
||||
wal.getScene()->addEntity("block")
|
||||
.addComponent<PositionComponent>(0, 0, 0)
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<CollisionComponent>(
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &, int) { nbCallbacksCalled++; },
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &, int) {
|
||||
@@ -156,6 +160,7 @@ TEST_CASE("Collision test callbacks args", "[Component][System]")
|
||||
|
||||
wal.getScene()->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<CollisionComponent>(
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
nbCallbacksCalled++;
|
||||
@@ -170,6 +175,7 @@ TEST_CASE("Collision test callbacks args", "[Component][System]")
|
||||
|
||||
wal.getScene()->addEntity("block")
|
||||
.addComponent<PositionComponent>(0, 0, 0)
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<CollisionComponent>(
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
nbCallbacksCalled++;
|
||||
@@ -193,6 +199,57 @@ TEST_CASE("Collision test callbacks args", "[Component][System]")
|
||||
REQUIRE(nbCallbacksCalled == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("Collision test callbacks args with only one movable entity", "[Component][System]")
|
||||
{
|
||||
int nbCallbacksCalled = 0;
|
||||
Wal wal;
|
||||
CollisionSystem collision(wal);
|
||||
MovableSystem movable(wal);
|
||||
|
||||
wal.changeScene(std::make_shared<Scene>());
|
||||
|
||||
wal.getScene()->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<CollisionComponent>(
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
nbCallbacksCalled++;
|
||||
REQUIRE(actual.getName() == "player");
|
||||
REQUIRE(other.getName() == "block");
|
||||
},
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
// lambda should not be called
|
||||
nbCallbacksCalled++;
|
||||
REQUIRE(other.getName() == "plfayer");
|
||||
REQUIRE(actual.getName() == "blofck");
|
||||
}, 0, 5.0);
|
||||
|
||||
wal.getScene()->addEntity("block")
|
||||
.addComponent<PositionComponent>(0, 0, 0)
|
||||
.addComponent<CollisionComponent>(
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
// lambda should not be called
|
||||
nbCallbacksCalled++;
|
||||
REQUIRE(other.getName() == "playefr");
|
||||
REQUIRE(actual.getName() == "blocfk");
|
||||
},
|
||||
[&nbCallbacksCalled](Entity &actual, const Entity &other, int) {
|
||||
nbCallbacksCalled++;
|
||||
REQUIRE(actual.getName() == "player");
|
||||
REQUIRE(other.getName() == "block");
|
||||
}, 0, 1);
|
||||
Entity &entity = wal.getScene()->getEntities().front();
|
||||
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
||||
|
||||
entity.getComponent<CollisionComponent>().bound.x = 5;
|
||||
entity.getComponent<CollisionComponent>().bound.y = 5;
|
||||
entity.getComponent<CollisionComponent>().bound.z = 5;
|
||||
|
||||
collision.update(std::chrono::nanoseconds(1));
|
||||
collision.fixedUpdate();
|
||||
REQUIRE(nbCallbacksCalled == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Vector round", "[Vector]")
|
||||
{
|
||||
Vector3f v(1.3, 1.5, 1.7);
|
||||
|
||||
Reference in New Issue
Block a user