From 2a82f46e498270ef8ad4a69c2a8536eb02ebf29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 10 Jun 2021 23:12:47 +0200 Subject: [PATCH 01/14] adding blowable tag to bonuses but the bomb exploded the bonuses instantly --- sources/Map/Map.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index fb9ef9b3..d8522618 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -53,6 +53,7 @@ namespace BBM return; wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) + .addComponent>() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); }) From 74072064ea92277ae2c76a036472641849698eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Fri, 11 Jun 2021 00:11:34 +0200 Subject: [PATCH 02/14] trying to save prevPos but it doesn't work --- .../System/BombHolder/BombHolderSystem.cpp | 31 +++++++++++++------ .../System/BombHolder/BombHolderSystem.hpp | 7 ++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 6a5dac6e..4a582b26 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -30,16 +30,16 @@ namespace BBM 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 radiusToDo, const Vector3f &posFrom) { - if (count <= 0) + if (radiusToDo <= 0) return; - wal.getSystem().dispatchEvent([position, count](WAL::Wal &wal) { + std::cout << "exploding at " << position << std::endl; + wal.getSystem().dispatchEvent([position, radiusToDo, posFrom](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { if (auto *health = entity.tryGetComponent()) @@ -47,10 +47,23 @@ 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); + const Vector3f expandVectors[] = { + {1, 0, 0}, + {-1, 0, 0}, + {0, 0, 1}, + {0, 0, -1}, + }; + + // should be true only at the first iteration + bool alwaysDispatch = position == posFrom; + + for (const auto &expandVector : expandVectors) { + Vector3f newPos = position + expandVector; + if (!alwaysDispatch && newPos == posFrom) { + continue; + } + _dispatchExplosion(newPos, wal, radiusToDo - 1, position); + } }); } @@ -59,7 +72,7 @@ namespace BBM bomb.scheduleDeletion(); auto position = bomb.getComponent().position.round(); auto explosionRadius = bomb.getComponent().explosionRadius; - _dispatchExplosion(position, wal, 3 + (explosionRadius - 3)); + _dispatchExplosion(position, wal, explosionRadius); } void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 481d7697..6c872ca8 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -22,7 +22,12 @@ 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 radiusToDo, const Vector3f &posFrom); + + //! @brief Wrapped call to specify default arg value + inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) { + return _dispatchExplosion(position, wal, radiusToDo, position); + }; //! @brief The method triggered when the bomb explode. static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &); From 5d478d8aabe8d5c1b72ce355d88d1b951731b1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Fri, 11 Jun 2021 11:29:33 +0200 Subject: [PATCH 03/14] collision system is now updating only movable entities --- sources/Models/Vector3.hpp | 5 +++ sources/System/Collision/CollisionSystem.cpp | 40 +++++++++++++------- sources/System/Collision/CollisionSystem.hpp | 5 ++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index a2266e07..8e8b4093 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -173,6 +173,11 @@ namespace BBM return Vector3(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) { return RAY::Vector3(this->x, this->y, this->z); diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index 0a321133..f2604254 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -23,7 +23,7 @@ namespace BBM return (overlapX && overlapY && overlapZ); } - void CollisionSystem::onFixedUpdate(WAL::ViewEntity &entity) + void CollisionSystem::onFixedUpdate(WAL::ViewEntity &entity) { unsigned int entityUid = entity->getUid(); auto &posA = entity.get(); @@ -33,8 +33,10 @@ namespace BBM Vector3f pointAy = pointA; Vector3f pointAz = pointA; - if (auto *movable = entity->tryGetComponent()) { - auto vel = movable->getVelocity(); + auto &movable = entity.get(); + 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()) { 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(collidedAxis)); diff --git a/sources/System/Collision/CollisionSystem.hpp b/sources/System/Collision/CollisionSystem.hpp index e1e75ede..d7d31595 100644 --- a/sources/System/Collision/CollisionSystem.hpp +++ b/sources/System/Collision/CollisionSystem.hpp @@ -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 + class CollisionSystem : public WAL::System { public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onFixedUpdate(WAL::ViewEntity &entity) override; //! @brief A default constructor explicit CollisionSystem(WAL::Wal &wal); From 0108002bb5bfe2487c7cb8b1aac9584fbf290b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Fri, 11 Jun 2021 14:45:44 +0200 Subject: [PATCH 04/14] testing bombs --- .../System/BombHolder/BombHolderSystem.cpp | 33 ++++++++----------- .../System/BombHolder/BombHolderSystem.hpp | 21 ++++++++++-- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 4a582b26..42750d19 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -34,12 +34,12 @@ namespace BBM : System(wal) {} - void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, const Vector3f &posFrom) + void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections) { if (radiusToDo <= 0) return; std::cout << "exploding at " << position << std::endl; - wal.getSystem().dispatchEvent([position, radiusToDo, posFrom](WAL::Wal &wal) { + wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { if (auto *health = entity.tryGetComponent()) @@ -47,22 +47,17 @@ namespace BBM return; } } - const Vector3f expandVectors[] = { - {1, 0, 0}, - {-1, 0, 0}, - {0, 0, 1}, - {0, 0, -1}, - }; - - // should be true only at the first iteration - bool alwaysDispatch = position == posFrom; - - for (const auto &expandVector : expandVectors) { - Vector3f newPos = position + expandVector; - if (!alwaysDispatch && newPos == posFrom) { - continue; - } - _dispatchExplosion(newPos, wal, radiusToDo - 1, position); + if (expansionDirections & ExpansionDirection::FRONT) { + _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::FRONT); + } + if (expansionDirections & ExpansionDirection::BACK) { + _dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::BACK); + } + if (expansionDirections & ExpansionDirection::LEFT) { + _dispatchExplosion(position + Vector3f{0, 0, 1}, wal, radiusToDo - 1, ExpansionDirection::LEFT); + } + if (expansionDirections & ExpansionDirection::RIGHT) { + _dispatchExplosion(position + Vector3f{0, 0, -1}, wal, radiusToDo - 1, ExpansionDirection::RIGHT); } }); } @@ -72,7 +67,7 @@ namespace BBM bomb.scheduleDeletion(); auto position = bomb.getComponent().position.round(); auto explosionRadius = bomb.getComponent().explosionRadius; - _dispatchExplosion(position, wal, explosionRadius); + _dispatchExplosion(position, wal, 2); } void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 6c872ca8..e7245eae 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -14,6 +14,15 @@ namespace BBM { + enum ExpansionDirection { + UP = 1, + DOWN = 2, + LEFT = 4, + RIGHT = 8, + FRONT = 16, + BACK = 32 + }; + //! @brief The system that allow one to place bombs. class BombHolderSystem : public WAL::System { @@ -22,11 +31,19 @@ namespace BBM void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); //! @brief Spawn a bomb at the specified position. - static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, const Vector3f &posFrom); + static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections); //! @brief Wrapped call to specify default arg value inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) { - return _dispatchExplosion(position, wal, radiusToDo, position); + return _dispatchExplosion(position, + wal, + radiusToDo, + static_cast(ExpansionDirection::DOWN + | ExpansionDirection::UP + | ExpansionDirection::FRONT + | ExpansionDirection::BACK + | ExpansionDirection::LEFT + | ExpansionDirection::RIGHT)); }; //! @brief The method triggered when the bomb explode. From dde64c99ab0cee8bf77376d6483d97d3e7d3f06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Fri, 11 Jun 2021 15:32:03 +0200 Subject: [PATCH 05/14] bonuses are collidable but the explosion is called multiple times --- sources/Map/Map.cpp | 2 ++ sources/System/BombHolder/BombHolderSystem.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index d8522618..0fa7b832 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "Component/Movable/MovableComponent.hpp" #include #include @@ -54,6 +55,7 @@ namespace BBM wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) .addComponent>() + .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); }) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 42750d19..6ad0ac60 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -38,7 +38,6 @@ namespace BBM { if (radiusToDo <= 0) return; - std::cout << "exploding at " << position << std::endl; wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { @@ -67,7 +66,7 @@ namespace BBM bomb.scheduleDeletion(); auto position = bomb.getComponent().position.round(); auto explosionRadius = bomb.getComponent().explosionRadius; - _dispatchExplosion(position, wal, 2); + _dispatchExplosion(position, wal, explosionRadius); } void BombHolderSystem::_spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id) From ae68d5ab6883336940376e30c703c6260f713eb2 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 10:07:08 +0200 Subject: [PATCH 06/14] add wires + bounding box drawing for 3D shapes/Models --- lib/Ray/sources/Drawables/3D/Cube.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Cube.hpp | 3 +++ lib/Ray/sources/Drawables/3D/Cylinder.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Cylinder.hpp | 2 ++ lib/Ray/sources/Drawables/3D/Sphere.cpp | 5 +++++ lib/Ray/sources/Drawables/3D/Sphere.hpp | 3 +++ lib/Ray/sources/Drawables/ADrawable3D.cpp | 3 +++ lib/Ray/sources/Drawables/ADrawable3D.hpp | 3 +++ lib/Ray/sources/Model/Model.cpp | 14 ++++++++++++++ lib/Ray/sources/Model/Model.hpp | 3 +++ sources/System/Renderer/RenderSystem.cpp | 4 +++- 11 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 6f651a15..7875e99a 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -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, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cube.hpp b/lib/Ray/sources/Drawables/3D/Cube.hpp index d1fff6f9..96347a95 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.hpp +++ b/lib/Ray/sources/Drawables/3D/Cube.hpp @@ -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; diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index 64db931d..6dfb2a1f 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -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, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.hpp b/lib/Ray/sources/Drawables/3D/Cylinder.hpp index dc09fb5d..32871514 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.hpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.hpp @@ -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; diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 7d23fc48..2949606e 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -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, GREEN); + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Sphere.hpp b/lib/Ray/sources/Drawables/3D/Sphere.hpp index d053ccf9..24c31a8b 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.hpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.hpp @@ -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; diff --git a/lib/Ray/sources/Drawables/ADrawable3D.cpp b/lib/Ray/sources/Drawables/ADrawable3D.cpp index 0fff69f8..fabc12fd 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -36,4 +36,7 @@ namespace RAY::Drawables this->_position = position; return *this; } + + void ADrawable3D::drawWiresOn(RAY::Window &) + {} } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index cc989fed..4c82ded6 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -30,6 +30,9 @@ 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; diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 9fd5b31e..2239c359 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -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, GREEN); + } + } + void Model::setShader(const RAY::Shader &shader) { this->_originalShader = this->_model->materials[0].shader; diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index d67706be..2bf6cf47 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -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; diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 07b64134..d901b115 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -40,6 +40,8 @@ namespace BBM modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); drawable.drawable->drawOn(this->_window); + if (this->_debugMode) + drawable.drawable->drawWiresOn(this->_window); if (modelShader) modelShader->model->resetShader(); } @@ -59,7 +61,7 @@ namespace BBM } } if (this->_debugMode) - this->_window.drawFPS(Vector2f()); + this->_window.drawFPS(Vector2f(10, 10)); this->_window.endDrawing(); } From ad71799c529fad33561db8c88e9cb3c22d46891a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 10:31:49 +0200 Subject: [PATCH 07/14] fixing unit tests --- tests/CollisionTest.cpp | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/CollisionTest.cpp b/tests/CollisionTest.cpp index bf5a31dc..6c0795c4 100644 --- a/tests/CollisionTest.cpp +++ b/tests/CollisionTest.cpp @@ -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()); wal.getScene()->addEntity("player") .addComponent() + .addComponent() .addComponent([](Entity &actual, const Entity &, int _) { try { auto &pos = actual.getComponent(); @@ -118,6 +121,7 @@ TEST_CASE("Collision test callbacks calls", "[Component][System]") wal.getScene()->addEntity("block") .addComponent(0, 0, 0) + .addComponent() .addComponent( [&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() + .addComponent() .addComponent( [&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(0, 0, 0) + .addComponent() .addComponent( [&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()); + + wal.getScene()->addEntity("player") + .addComponent() + .addComponent() + .addComponent( + [&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(0, 0, 0) + .addComponent( + [&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().position == Vector3f()); + + entity.getComponent().bound.x = 5; + entity.getComponent().bound.y = 5; + entity.getComponent().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); From 7fb62d10f4a763fa4b7d39057e627c66ee66e47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 10:47:12 +0200 Subject: [PATCH 08/14] indent issues --- .../System/BombHolder/BombHolderSystem.cpp | 27 ++++++++------ .../System/BombHolder/BombHolderSystem.hpp | 35 ++++++++++++------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 4a575b8b..db3c5c55 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -22,20 +22,23 @@ 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(); 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(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections) + void BombHolderSystem::_dispatchExplosion(const Vector3f &position, + WAL::Wal &wal, + int radiusToDo, + ExpansionDirection expansionDirections) { if (radiusToDo <= 0) return; @@ -45,7 +48,8 @@ namespace BBM explosion.scheduleDeletion(); }) .addComponent("assets/bombs/explosion/explosion.glb", false, - std::make_pair(MAP_DIFFUSE, "assets/bombs/explosion/blast.png")); + std::make_pair(MAP_DIFFUSE, + "assets/bombs/explosion/blast.png")); wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { @@ -83,16 +87,19 @@ namespace BBM .addComponent(position.round()) .addComponent(holder.damage, holder.explosionRadius, id) .addComponent(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) - .addComponent(WAL::Callback(), - &BombHolderSystem::_bombCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &BombHolderSystem::_bombCollide, 0.25, .75) .addComponent("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 &entity, - std::chrono::nanoseconds dtime) + void + BombHolderSystem::onUpdate(WAL::ViewEntity &entity, + std::chrono::nanoseconds dtime) { auto &holder = entity.get(); auto &position = entity.get(); diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index e7245eae..3eca4151 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -14,7 +14,8 @@ namespace BBM { - enum ExpansionDirection { + enum ExpansionDirection + { UP = 1, DOWN = 2, LEFT = 4, @@ -31,26 +32,33 @@ namespace BBM void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); //! @brief Spawn a bomb at the specified position. - static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, ExpansionDirection expansionDirections); + static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, + ExpansionDirection expansionDirections); //! @brief Wrapped call to specify default arg value - inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) { + inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) + { return _dispatchExplosion(position, - wal, - radiusToDo, - static_cast(ExpansionDirection::DOWN - | ExpansionDirection::UP - | ExpansionDirection::FRONT - | ExpansionDirection::BACK - | ExpansionDirection::LEFT - | ExpansionDirection::RIGHT)); + wal, + radiusToDo, + static_cast( + 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; @@ -61,10 +69,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; }; From 6a9a09652aa00db9cc3530c7b6a3450b6d188ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 10:51:27 +0200 Subject: [PATCH 09/14] more indent fixes --- sources/System/BombHolder/BombHolderSystem.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index db3c5c55..7aca6a9a 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -48,8 +48,10 @@ namespace BBM explosion.scheduleDeletion(); }) .addComponent("assets/bombs/explosion/explosion.glb", false, - std::make_pair(MAP_DIFFUSE, - "assets/bombs/explosion/blast.png")); + std::make_pair( + MAP_DIFFUSE, + "assets/bombs/explosion/blast.png" + )); wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { @@ -91,8 +93,10 @@ namespace BBM WAL::Callback(), &BombHolderSystem::_bombCollide, 0.25, .75) .addComponent("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; } From a3236ffba6a29002da19fd06e2eeb433bd4b133d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 11:43:39 +0200 Subject: [PATCH 10/14] debug color is now a memeber of the drawable 3D class --- lib/Ray/sources/Drawables/3D/Cube.cpp | 2 +- lib/Ray/sources/Drawables/3D/Cylinder.cpp | 2 +- lib/Ray/sources/Drawables/3D/Sphere.cpp | 2 +- lib/Ray/sources/Drawables/ADrawable3D.hpp | 3 +++ lib/Ray/sources/Model/Model.cpp | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 7875e99a..1af236d1 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -33,6 +33,6 @@ namespace RAY::Drawables::Drawables3D void Cube::drawWiresOn(RAY::Window &) { - DrawCubeWiresV(this->_position, this->_dimensions, GREEN); + DrawCubeWiresV(this->_position, this->_dimensions, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index 6dfb2a1f..8e2ff386 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -55,6 +55,6 @@ namespace RAY::Drawables::Drawables3D void Cylinder::drawWiresOn(RAY::Window &) { - DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, GREEN); + DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 2949606e..f87c3fa5 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -33,6 +33,6 @@ namespace RAY::Drawables::Drawables3D void Sphere::drawWiresOn(RAY::Window &) { - DrawSphereWires(this->_position, this->_radius, 10, 10, GREEN); + DrawSphereWires(this->_position, this->_radius, 10, 10, this->_debugColor); } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index 4c82ded6..3c52f5de 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -52,6 +52,9 @@ namespace RAY::Drawables { //! @brief Color of the ADrawable Color _color; + //! @brief Color of the ADrawable's Debug + Color _debugColor = GREEN; + }; }; diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 2239c359..fefa29ea 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -124,7 +124,7 @@ namespace RAY::Drawables::Drawables3D box.max.x += this->_position.x; box.max.y += this->_position.y; box.max.z += this->_position.z; - DrawBoundingBox(box, GREEN); + DrawBoundingBox(box, this->_debugColor); } } From a36ab11b6d38e94321d9e9e7af3b56715712b379 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 14 Jun 2021 13:59:05 +0200 Subject: [PATCH 11/14] draws bounding box + contours --- sources/System/Renderer/RenderSystem.cpp | 21 +++++++++++++++++---- sources/System/Renderer/RenderSystem.hpp | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index d901b115..b6a6e735 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -11,8 +11,8 @@ #include #include "Drawables/ADrawable3D.hpp" #include "Component/Shaders/ShaderComponent.hpp" - - +#include +#include "Models/Vector3.hpp" #include "Component/Collision/CollisionComponent.hpp" namespace BBM @@ -26,6 +26,19 @@ 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(); + + //draws hitbox + if (dimsComponent) { + RAY::Drawables::Drawables3D::Cube boundingBox(posComponent.position, dimsComponent->bound, WHITE); + boundingBox.drawWiresOn(this->_window); + } + //draws models contours + drawable.drawable->drawWiresOn(this->_window); + } + void RenderSystem::onSelfUpdate() { this->_camera.update(); @@ -39,9 +52,9 @@ namespace BBM if (modelShader) modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); - drawable.drawable->drawOn(this->_window); if (this->_debugMode) - drawable.drawable->drawWiresOn(this->_window); + this->drawBoundingBox(entity, pos, drawable); + drawable.drawable->drawOn(this->_window); if (modelShader) modelShader->model->resetShader(); } diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index e790a741..bff17267 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -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 From a229452dc40bbe1300bcfd54473d19a50196b9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 14:41:04 +0200 Subject: [PATCH 12/14] adding red color for collisions boxes --- lib/Ray/sources/Drawables/ADrawable3D.cpp | 11 +++++++++++ lib/Ray/sources/Drawables/ADrawable3D.hpp | 8 +++++++- sources/Map/Map.cpp | 2 +- sources/System/Renderer/RenderSystem.cpp | 5 +++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/Ray/sources/Drawables/ADrawable3D.cpp b/lib/Ray/sources/Drawables/ADrawable3D.cpp index fabc12fd..2d7cfaf2 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -39,4 +39,15 @@ namespace RAY::Drawables 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; + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index 3c52f5de..58aa5359 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -35,10 +35,16 @@ namespace RAY::Drawables { //! @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; diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 9bdc22ae..49841dda 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -165,7 +165,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(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index b6a6e735..d21065c2 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -33,6 +33,7 @@ namespace BBM //draws hitbox if (dimsComponent) { RAY::Drawables::Drawables3D::Cube boundingBox(posComponent.position, dimsComponent->bound, WHITE); + boundingBox.setDebugColor(RED); boundingBox.drawWiresOn(this->_window); } //draws models contours @@ -52,11 +53,11 @@ namespace BBM if (modelShader) modelShader->model->setShader(modelShader->getShader()); drawable.drawable->setPosition(pos.position); - if (this->_debugMode) - this->drawBoundingBox(entity, pos, drawable); drawable.drawable->drawOn(this->_window); if (modelShader) modelShader->model->resetShader(); + if (this->_debugMode) + this->drawBoundingBox(entity, pos, drawable); } this->_window.unuseCamera(); From 17fb5da6dcb4876f354b750be72782842627d8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 14:54:37 +0200 Subject: [PATCH 13/14] fixing naming issues and default args --- .../System/BombHolder/BombHolderSystem.cpp | 14 ++++---- .../System/BombHolder/BombHolderSystem.hpp | 34 ++++++++----------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 7aca6a9a..6fe1055d 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -37,10 +37,10 @@ namespace BBM void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, - int radiusToDo, + int size, ExpansionDirection expansionDirections) { - if (radiusToDo <= 0) + if (size <= 0) return; wal.getScene()->scheduleNewEntity("explosion") .addComponent(position) @@ -52,7 +52,7 @@ namespace BBM MAP_DIFFUSE, "assets/bombs/explosion/blast.png" )); - wal.getSystem().dispatchEvent([position, radiusToDo, expansionDirections](WAL::Wal &wal) { + wal.getSystem().dispatchEvent([position, size, expansionDirections](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { if (auto *health = entity.tryGetComponent()) @@ -61,16 +61,16 @@ namespace BBM } } if (expansionDirections & ExpansionDirection::FRONT) { - _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::FRONT); + _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, size - 1, ExpansionDirection::FRONT); } if (expansionDirections & ExpansionDirection::BACK) { - _dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, radiusToDo - 1, ExpansionDirection::BACK); + _dispatchExplosion(position + Vector3f{-1, 0, 0}, wal, size - 1, ExpansionDirection::BACK); } if (expansionDirections & ExpansionDirection::LEFT) { - _dispatchExplosion(position + Vector3f{0, 0, 1}, wal, radiusToDo - 1, ExpansionDirection::LEFT); + _dispatchExplosion(position + Vector3f{0, 0, 1}, wal, size - 1, ExpansionDirection::LEFT); } if (expansionDirections & ExpansionDirection::RIGHT) { - _dispatchExplosion(position + Vector3f{0, 0, -1}, wal, radiusToDo - 1, ExpansionDirection::RIGHT); + _dispatchExplosion(position + Vector3f{0, 0, -1}, wal, size - 1, ExpansionDirection::RIGHT); } }); } diff --git a/sources/System/BombHolder/BombHolderSystem.hpp b/sources/System/BombHolder/BombHolderSystem.hpp index 3eca4151..c7fc11e7 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -24,6 +24,12 @@ namespace BBM BACK = 32 }; + //! @brief Ta avoid explicit casting + inline ExpansionDirection operator|(ExpansionDirection a, ExpansionDirection b) + { + return static_cast(static_cast(a) | static_cast(b)); + } + //! @brief The system that allow one to place bombs. class BombHolderSystem : public WAL::System { @@ -32,25 +38,15 @@ namespace BBM void _spawnBomb(Vector3f position, BombHolderComponent &holder, unsigned id); //! @brief Spawn a bomb at the specified position. - static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, - ExpansionDirection expansionDirections); - - //! @brief Wrapped call to specify default arg value - inline static void _dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo) - { - return _dispatchExplosion(position, - wal, - radiusToDo, - static_cast( - ExpansionDirection::DOWN - | ExpansionDirection::UP - | ExpansionDirection::FRONT - | ExpansionDirection::BACK - | ExpansionDirection::LEFT - | ExpansionDirection::RIGHT - ) - ); - }; + 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 &); From b204f480590f44b0efaf9ac6a9a80d850b7c48b7 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 14 Jun 2021 17:21:10 +0200 Subject: [PATCH 14/14] Adding colors to players --- sources/Component/Lobby/LobbyComponent.cpp | 7 ++-- sources/Component/Lobby/LobbyComponent.hpp | 4 ++- sources/Runner/LobbyScene.cpp | 5 ++- sources/System/Lobby/LobbySystem.cpp | 38 ++++++++++++++++------ sources/System/Lobby/LobbySystem.hpp | 8 +++-- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/sources/Component/Lobby/LobbyComponent.cpp b/sources/Component/Lobby/LobbyComponent.cpp index 9f46bfb4..a945f112 100644 --- a/sources/Component/Lobby/LobbyComponent.cpp +++ b/sources/Component/Lobby/LobbyComponent.cpp @@ -6,14 +6,15 @@ namespace BBM { - LobbyComponent::LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton) + LobbyComponent::LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile) : WAL::Component(entity), playerID(playerID), - readyButton(readyButton) + readyButton(readyButton), + coloredTile(coloredTile) {} WAL::Component *LobbyComponent::clone(WAL::Entity &entity) const { - return new LobbyComponent(entity, this->playerID, this->readyButton); + return new LobbyComponent(entity, this->playerID, this->readyButton, this->coloredTile); } } \ No newline at end of file diff --git a/sources/Component/Lobby/LobbyComponent.hpp b/sources/Component/Lobby/LobbyComponent.hpp index 18647649..4061d1ce 100644 --- a/sources/Component/Lobby/LobbyComponent.hpp +++ b/sources/Component/Lobby/LobbyComponent.hpp @@ -25,13 +25,15 @@ namespace BBM bool ready = false; //! @brief The entity containing the ready display. WAL::Entity &readyButton; + //! @brief The colored rectangle behind the player. + WAL::Entity &coloredTile; //! @brief The time of last input that this lobby player has made. std::chrono::time_point lastInput; Component *clone(WAL::Entity &entity) const override; //! @brief Create a new lobby component. - explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton); + explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile); //! @brief A lobby component is copyable. LobbyComponent(const LobbyComponent &) = default; //! @brief A default destructor diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index a133a35f..54e45191 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -133,18 +133,17 @@ namespace BBM entity.getComponent().drawable->setColor(ORANGE); }); - static const std::vector colors = { BLUE, RED, GREEN, YELLOW }; for (int i = 0; i < 4; i++) { auto &playerTile = scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) - .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), colors[i]); + .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), RAY::Color(0, 0, 0, 0)); auto &player = scene->addEntity("player") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) .addComponent("assets/player/icons/none.png"); auto &ready = scene->addEntity("ready") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) .addComponent(); - player.addComponent(i, ready); + player.addComponent(i, ready, playerTile); } scene->addEntity("camera") .addComponent(8, 20, 7) diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 8c12ce79..3f9df0c7 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -19,7 +19,7 @@ namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { - std::vector LobbySystem::_colors = { + std::array LobbySystem::_colors = { "blue", "red", "green", @@ -28,6 +28,15 @@ namespace BBM "yellow" }; + std::array LobbySystem::_rayColors = { + BLUE, + RED, + GREEN, + // PURPLE, + // SKYBLUE, + YELLOW + }; + LobbySystem::LobbySystem(WAL::Wal &wal) : System(wal) {} @@ -35,7 +44,16 @@ namespace BBM void LobbySystem::_nextColor(WAL::ViewEntity &entity) { auto &lobby = entity.get(); + if (lobby.color != -1) + this->_colorTaken[lobby.color] = false; + do { + lobby.color++; + if (lobby.color >= this->_colorTaken.size()) + lobby.color = 0; + } while (this->_colorTaken[lobby.color]); + this->_colorTaken[lobby.color] = true; entity.get().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); + lobby.coloredTile.getComponent().drawable->setColor(_rayColors[lobby.color]); } void LobbySystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) @@ -55,21 +73,19 @@ namespace BBM })) return; lobby.lastInput = lastTick; - lobby.color = 0; - entity.get().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); - - // this->_nextColor(entity); + lobby.color = -1; + this->_nextColor(entity); lobby.layout = controller.layout; controller.jump = false; return; } -// if (controller.bomb) -// this->_nextColor(entity); } } for (auto &[_, controller] : this->_wal.getScene()->view()) { - if (controller.layout == lobby.layout && controller.jump && !lobby.ready) { + if (controller.layout != lobby.layout) + continue; + if (controller.jump && !lobby.ready) { lobby.ready = true; lobby.lastInput = lastTick; controller.jump = false; @@ -78,11 +94,13 @@ namespace BBM if (texture) texture->use("assets/player/icons/ready.png"); } + if (controller.bomb && !lobby.ready) { + lobby.lastInput = lastTick; + this->_nextColor(entity); + } } } - - void LobbySystem::onSelfUpdate() { auto &view = this->_wal.getScene()->view, Drawable2DComponent>(); diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index b1b3a495..b1eb7d8c 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -20,9 +20,13 @@ namespace BBM //! @brief Add a controller for the player. static void _addController(WAL::Entity &player, ControllableComponent::Layout layout); - static void _nextColor(WAL::ViewEntity &entity); + void _nextColor(WAL::ViewEntity &entity); - static std::vector _colors; + static std::array _colors; + + static std::array _rayColors; + + std::array _colorTaken = {}; public: //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;