diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index 6f651a15..1af236d1 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, this->_debugColor); + } } \ 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..8e2ff386 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, this->_debugColor); + } } \ 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..f87c3fa5 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, this->_debugColor); + } } \ 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..2d7cfaf2 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -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; + } } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index cc989fed..58aa5359 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -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; + }; }; diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index 9fd5b31e..fefa29ea 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, this->_debugColor); + } + } + 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/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/Map/Map.cpp b/sources/Map/Map.cpp index 9bdc22ae..323fadb1 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 @@ -53,6 +54,8 @@ namespace BBM return; wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) + .addComponent>() + .addComponent() .addComponent(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(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); 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/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/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index d91c2a27..6fe1055d 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -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(); 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(position) @@ -46,8 +48,11 @@ namespace BBM explosion.scheduleDeletion(); }) .addComponent("assets/bombs/explosion/explosion.glb", false, - std::make_pair(MAP_DIFFUSE, "assets/bombs/explosion/blast.png")); - wal.getSystem().dispatchEvent([position, count](WAL::Wal &wal) { + std::make_pair( + MAP_DIFFUSE, + "assets/bombs/explosion/blast.png" + )); + 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()) @@ -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().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) @@ -76,16 +89,21 @@ 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 481d7697..c7fc11e7 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -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(static_cast(a) | static_cast(b)); + } + //! @brief The system that allow one to place bombs. class BombHolderSystem : public WAL::System { @@ -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; }; 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); 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; diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 07b64134..d21065c2 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,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(); + + //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(); } 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 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);