From b552ee3d45462eccad3dccd6a722fefb02a95612 Mon Sep 17 00:00:00 2001 From: Askou Date: Wed, 9 Jun 2021 11:57:25 +0200 Subject: [PATCH 01/22] add collision for bumper and hole --- sources/Map/Map.cpp | 48 ++++++++++++++++++++++++++------------- sources/Map/Map.hpp | 11 +++++++++ sources/Runner/Runner.cpp | 4 ++-- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 5e8a9a2e..23c14dbe 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -12,6 +12,28 @@ namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { + void MapGenerator::bumperCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *movable = entity.tryGetComponent(); + + if (!movable) + return; + movable->_velocity.y = 0.5; + } + + void MapGenerator::holeCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *health = entity.tryGetComponent(); + + if (!health) + return; + health->takeDmg(health->getHealthPoint()); + } + void MapGenerator::wallCollide(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) @@ -23,7 +45,7 @@ namespace BBM if (collidedAxis & CollisionComponent::CollidedAxis::X) mov->_velocity.x = 0; if (collidedAxis & CollisionComponent::CollidedAxis::Y) - mov->_velocity.x = 0; + mov->_velocity.y = 0; if (collidedAxis & CollisionComponent::CollidedAxis::Z) mov->_velocity.z = 0; } @@ -200,19 +222,16 @@ namespace BBM WAL::Entity &holeEntity = scene->addEntity("Hole Block"); - holeEntity.addComponent(Vector3f(coords.x, coords.y - 1, coords.z)); - + holeEntity.addComponent(Vector3f(coords.x, coords.y - 1, coords.z)) + .addComponent( + WAL::Callback(), + &MapGenerator::holeCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 1.75, 0.75)); if (coords.y == 0) holeEntity.addComponent(holeObj, std::make_pair(MAP_DIFFUSE, holePng)); else holeEntity.addComponent(secondFloorObj, std::make_pair(MAP_DIFFUSE, secondFloorPng)); - /*.addComponent([](WAL::Entity &other, const WAL::Entity &entity) { - if (other.hasComponent()) { - auto &health = other.getComponent(); - health.takeDmg(health.getHealthPoint()); - } - }, [](WAL::Entity &other, const WAL::Entity &entity){}); */ + } void MapGenerator::createBumper(Vector3f coords, std::shared_ptr scene) @@ -222,13 +241,10 @@ namespace BBM scene->addEntity("Bumper Block") .addComponent(Vector3f(coords.x, coords.y, coords.z)) - .addComponent(bumperObj, std::make_pair(MAP_DIFFUSE, bumperPng)); - /* .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { - if (other.hasComponent()) { - auto &movable = other.getComponent(); - movable.addForce(Vector3f(0, 5, 0)); - } - }); */ + .addComponent(bumperObj, std::make_pair(MAP_DIFFUSE, bumperPng)) + .addComponent( + WAL::Callback(), + &MapGenerator::bumperCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(0.75, 0.75, 0.75)); } void MapGenerator::createStairs(Vector3f coords, std::shared_ptr scene) diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 4a961cbc..328fa506 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -159,11 +159,22 @@ namespace BBM static const std::string secondFloorHolePath; public: + static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis); + static void wallDestroyed(WAL::Entity &entity); + static void holeCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); + + static void bumperCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); + + //! @param width Width of the map //! @param height Height of the map diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 591ce261..5e810675 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -87,8 +87,8 @@ namespace BBM animation.setAnimIndex(5); }); scene->addEntity("camera") - .addComponent(8, 20, 7) - .addComponent(Vector3f(8, 0, 8)); + .addComponent(8, 4, -15) + .addComponent(Vector3f(8, 3, 8)); /*scene->addEntity("cube") .addComponent(-5, 0, -5) .addComponent(Vector3f(0, 0, 0), Vector3f(3, 3, 3), RED) From 1470371c10f6b6e14d8cdf962fdf9a4d7b0fa8a4 Mon Sep 17 00:00:00 2001 From: Askou Date: Wed, 9 Jun 2021 11:58:27 +0200 Subject: [PATCH 02/22] reposition camera --- sources/Runner/Runner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 5e810675..591ce261 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -87,8 +87,8 @@ namespace BBM animation.setAnimIndex(5); }); scene->addEntity("camera") - .addComponent(8, 4, -15) - .addComponent(Vector3f(8, 3, 8)); + .addComponent(8, 20, 7) + .addComponent(Vector3f(8, 0, 8)); /*scene->addEntity("cube") .addComponent(-5, 0, -5) .addComponent(Vector3f(0, 0, 0), Vector3f(3, 3, 3), RED) From d17a410a656b7932c05209921d89d094983435e6 Mon Sep 17 00:00:00 2001 From: Askou Date: Wed, 9 Jun 2021 17:23:55 +0200 Subject: [PATCH 03/22] basic gravity --- CMakeLists.txt | 2 ++ .../Component/Gravity/GravityComponent.cpp | 17 ++++++++++ .../Component/Gravity/GravityComponent.hpp | 32 +++++++++++++++++++ sources/Runner/Runner.cpp | 4 +++ sources/System/Gravity/GravitySystem.cpp | 21 ++++++++++++ sources/System/Gravity/GravitySystem.hpp | 30 +++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100644 sources/Component/Gravity/GravityComponent.cpp create mode 100644 sources/Component/Gravity/GravityComponent.hpp create mode 100644 sources/System/Gravity/GravitySystem.cpp create mode 100644 sources/System/Gravity/GravitySystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d7dc8112..8ae95107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,8 @@ set(SOURCES sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.cpp + sources/Component/Gravity/GravityComponent.cpp + sources/System/Gravity/GravitySystem.cpp ) add_executable(bomberman diff --git a/sources/Component/Gravity/GravityComponent.cpp b/sources/Component/Gravity/GravityComponent.cpp new file mode 100644 index 00000000..a6ee1db4 --- /dev/null +++ b/sources/Component/Gravity/GravityComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#include "GravityComponent.hpp" + +namespace BBM +{ + GravityComponent::GravityComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *GravityComponent::clone(WAL::Entity &entity) const + { + return new GravityComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/Gravity/GravityComponent.hpp b/sources/Component/Gravity/GravityComponent.hpp new file mode 100644 index 00000000..f2b6a368 --- /dev/null +++ b/sources/Component/Gravity/GravityComponent.hpp @@ -0,0 +1,32 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#pragma once + +#include +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" + +namespace BBM +{ + class GravityComponent : public WAL::Component + { + public: + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Constructor + GravityComponent(WAL::Entity &entity); + + //! @brief A Gravity component can't be instantiated, it should be derived. + GravityComponent(const GravityComponent &) = default; + + //! @brief default destructor + ~GravityComponent() override = default; + + //! @brief A Gravity component can't be assigned + GravityComponent &operator=(const GravityComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 2ee46062..de4c821f 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -39,6 +39,8 @@ #include "Component/Sound/SoundComponent.hpp" #include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Music/MusicSystem.hpp" +#include "Component/Gravity/GravityComponent.hpp" +#include "System/Gravity/GravitySystem.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -66,6 +68,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem(); } @@ -101,6 +104,7 @@ namespace BBM .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() .addComponent(soundPath) + .addComponent() .addComponent() .addComponent(1, [](WAL::Entity &entity) { auto &animation = entity.getComponent(); diff --git a/sources/System/Gravity/GravitySystem.cpp b/sources/System/Gravity/GravitySystem.cpp new file mode 100644 index 00000000..8e0801e1 --- /dev/null +++ b/sources/System/Gravity/GravitySystem.cpp @@ -0,0 +1,21 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#include "GravitySystem.hpp" + +namespace BBM +{ + GravitySystem::GravitySystem(WAL::Wal &wal) + : System(wal) + {} + + void GravitySystem::onFixedUpdate(WAL::ViewEntity &entity) + { + auto &movable = entity.get(); + auto &position = entity.get(); + + if (position.getY() > 0) + movable.addForce(Vector3f(0, -0.5, 0)); + } +} \ No newline at end of file diff --git a/sources/System/Gravity/GravitySystem.hpp b/sources/System/Gravity/GravitySystem.hpp new file mode 100644 index 00000000..59963ac7 --- /dev/null +++ b/sources/System/Gravity/GravitySystem.hpp @@ -0,0 +1,30 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#pragma once + +#include "Component/Movable/MovableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Gravity/GravityComponent.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle Gravity entities. + class GravitySystem : public WAL::System + { + public: + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entity) override; + + //! @brief A default constructor + explicit GravitySystem(WAL::Wal &wal); + //! @brief A Gravity system is copy constructable + GravitySystem(const GravitySystem &) = default; + //! @brief A default destructor + ~GravitySystem() override = default; + //! @brief A system is not assignable. + GravitySystem &operator=(const GravitySystem &) = delete; + }; +} \ No newline at end of file From 4a1e7b085fc78b9aa02bf359cb1922a28fb85230 Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 10 Jun 2021 11:24:47 +0200 Subject: [PATCH 04/22] bumperComponent + fix map --- CMakeLists.txt | 6 +++ .../BumperTimer/BumperTimerComponent.cpp | 17 ++++++++ .../BumperTimer/BumperTimerComponent.hpp | 41 +++++++++++++++++++ .../Component/Gravity/GravityComponent.hpp | 1 - sources/Map/Map.cpp | 32 +++++++++++++-- sources/Runner/Runner.cpp | 6 ++- .../System/BumperTimer/BumperTimerSystem.cpp | 25 +++++++++++ .../System/BumperTimer/BumperTimerSystem.hpp | 29 +++++++++++++ sources/System/Gravity/GravitySystem.cpp | 2 +- 9 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 sources/Component/BumperTimer/BumperTimerComponent.cpp create mode 100644 sources/Component/BumperTimer/BumperTimerComponent.hpp create mode 100644 sources/System/BumperTimer/BumperTimerSystem.cpp create mode 100644 sources/System/BumperTimer/BumperTimerSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae95107..6fc419f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,8 +92,14 @@ set(SOURCES sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.cpp + sources/Component/Gravity/GravityComponent.hpp sources/Component/Gravity/GravityComponent.cpp + sources/System/Gravity/GravitySystem.hpp sources/System/Gravity/GravitySystem.cpp + sources/Component/BumperTimer/BumperTimerComponent.hpp + sources/Component/BumperTimer/BumperTimerComponent.cpp + sources/System/BumperTimer/BumperTimerSystem.hpp + sources/System/BumperTimer/BumperTimerSystem.cpp ) add_executable(bomberman diff --git a/sources/Component/BumperTimer/BumperTimerComponent.cpp b/sources/Component/BumperTimer/BumperTimerComponent.cpp new file mode 100644 index 00000000..1d661395 --- /dev/null +++ b/sources/Component/BumperTimer/BumperTimerComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#include "BumperTimerComponent.hpp" + +namespace BBM +{ + BumperTimerComponent::BumperTimerComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *BumperTimerComponent::clone(WAL::Entity &entity) const + { + return new BumperTimerComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/BumperTimer/BumperTimerComponent.hpp b/sources/Component/BumperTimer/BumperTimerComponent.hpp new file mode 100644 index 00000000..dbeba275 --- /dev/null +++ b/sources/Component/BumperTimer/BumperTimerComponent.hpp @@ -0,0 +1,41 @@ +// +// Created by Tom Augier on 2021-05-20. +// + +#pragma once + +#include +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" + +using namespace std::chrono_literals; + +namespace BBM +{ + class BumperTimerComponent : public WAL::Component + { + public: + + + bool _isReseting = false; + //! @brief The number of seconds of each refill. This variable is used to reset the nextBombRefill value. + std::chrono::nanoseconds resetRate = 1500ms; + //! @brief The number of nanosecond before the next bomb refill. + std::chrono::nanoseconds nextReset = resetRate; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Constructor + BumperTimerComponent(WAL::Entity &entity); + + //! @brief A BumperTimer component can't be instantiated, it should be derived. + BumperTimerComponent(const BumperTimerComponent &) = default; + + //! @brief default destructor + ~BumperTimerComponent() override = default; + + //! @brief A BumperTimer component can't be assigned + BumperTimerComponent &operator=(const BumperTimerComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Gravity/GravityComponent.hpp b/sources/Component/Gravity/GravityComponent.hpp index f2b6a368..59f7cc89 100644 --- a/sources/Component/Gravity/GravityComponent.hpp +++ b/sources/Component/Gravity/GravityComponent.hpp @@ -4,7 +4,6 @@ #pragma once -#include #include "Component/Component.hpp" #include "Entity/Entity.hpp" diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index fb26dd2f..9d76bf45 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -7,6 +7,7 @@ #include "System/Collision/CollisionSystem.hpp" #include "Map.hpp" #include +#include namespace RAY3D = RAY::Drawables::Drawables3D; @@ -17,10 +18,14 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis) { auto *movable = entity.tryGetComponent(); + auto *bumperTimer = entity.tryGetComponent(); - if (!movable) + if (!movable || !bumperTimer) return; - movable->_velocity.y = 0.5; + if (!bumperTimer->_isReseting) { + movable->_velocity.y = 1.5; + bumperTimer->_isReseting = true; + } } void MapGenerator::holeCollide(WAL::Entity &entity, @@ -197,7 +202,10 @@ namespace BBM scene->addEntity("Upper Floor") .addComponent(Vector3f(coords)) - .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); + .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, 0.75); } @@ -308,9 +316,25 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height) { map[std::make_tuple(0, 0, 0)] = SPAWNER; + map[std::make_tuple(0, 0, 1)] = SPAWNER; + map[std::make_tuple(0, 0, 2)] = SPAWNER; + map[std::make_tuple(1, 0, 0)] = SPAWNER; + map[std::make_tuple(2, 0, 0)] = SPAWNER; map[std::make_tuple(width, 0, 0)] = SPAWNER; + map[std::make_tuple(width - 1, 0, 0)] = SPAWNER; + map[std::make_tuple(width - 2, 0, 0)] = SPAWNER; + map[std::make_tuple(width, 0, 1)] = SPAWNER; + map[std::make_tuple(width, 0, 2)] = SPAWNER; map[std::make_tuple(0, 0, height)] = SPAWNER; + map[std::make_tuple(1, 0, height)] = SPAWNER; + map[std::make_tuple(2, 0, height)] = SPAWNER; + map[std::make_tuple(0, 0, height - 1)] = SPAWNER; + map[std::make_tuple(0, 0, height - 2)] = SPAWNER; map[std::make_tuple(width, 0, height)] = SPAWNER; + map[std::make_tuple(width, 0, height - 1)] = SPAWNER; + map[std::make_tuple(width, 0, height - 2)] = SPAWNER; + map[std::make_tuple(width - 1, 0, height)] = SPAWNER; + map[std::make_tuple(width - 2, 0, height)] = SPAWNER; return map; } @@ -321,6 +345,8 @@ namespace BBM for (int j = 0; j < height; j++) { if (map[std::make_tuple(i, 0, j)] == BREAKABLE && map[std::make_tuple(i, -1, j)] == BUMPER) map[std::make_tuple(i, 0, j)] = NOTHING; + if (map[std::make_tuple(i, 1, j)] == BREAKABLE && isCloseToBlockType(map, i, -1, j, BUMPER)) + map[std::make_tuple(i, 1, j)] = NOTHING; } return (map); } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index de4c821f..5cdcbd3a 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -41,6 +41,8 @@ #include "System/Music/MusicSystem.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "System/Gravity/GravitySystem.hpp" +#include "Component/BumperTimer/BumperTimerComponent.hpp" +#include "System/BumperTimer/BumperTimerSystem.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -69,6 +71,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem(); } @@ -92,7 +95,7 @@ namespace BBM //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; scene->addEntity("player") - .addComponent() + .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() @@ -106,6 +109,7 @@ namespace BBM .addComponent(soundPath) .addComponent() .addComponent() + .addComponent() .addComponent(1, [](WAL::Entity &entity) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); diff --git a/sources/System/BumperTimer/BumperTimerSystem.cpp b/sources/System/BumperTimer/BumperTimerSystem.cpp new file mode 100644 index 00000000..36c8b93f --- /dev/null +++ b/sources/System/BumperTimer/BumperTimerSystem.cpp @@ -0,0 +1,25 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#include "BumperTimerSystem.hpp" + +namespace BBM +{ + BumperTimerSystem::BumperTimerSystem(WAL::Wal &wal) + : System(wal) + {} + + void BumperTimerSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) + { + auto &bumperTimer = entity.get(); + + if (bumperTimer._isReseting) { + bumperTimer.nextReset -= dtime; + if (bumperTimer.nextReset <= 0ns) { + bumperTimer.nextReset = bumperTimer.resetRate; + bumperTimer._isReseting = false; + } + } + } +} \ No newline at end of file diff --git a/sources/System/BumperTimer/BumperTimerSystem.hpp b/sources/System/BumperTimer/BumperTimerSystem.hpp new file mode 100644 index 00000000..d1bbe2e8 --- /dev/null +++ b/sources/System/BumperTimer/BumperTimerSystem.hpp @@ -0,0 +1,29 @@ +// +// Created by Tom Augier on 2021-06-09. +// + +#pragma once + +#include "Component/Movable/MovableComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/BumperTimer/BumperTimerComponent.hpp" +#include "System/System.hpp" + +namespace BBM +{ + //! @brief A system to handle BumperTimer entities. + class BumperTimerSystem : public WAL::System + { + public: + //! @inherit + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; + //! @brief A default constructor + explicit BumperTimerSystem(WAL::Wal &wal); + //! @brief A BumperTimer system is copy constructable + BumperTimerSystem(const BumperTimerSystem &) = default; + //! @brief A default destructor + ~BumperTimerSystem() override = default; + //! @brief A system is not assignable. + BumperTimerSystem &operator=(const BumperTimerSystem &) = delete; + }; +} \ No newline at end of file diff --git a/sources/System/Gravity/GravitySystem.cpp b/sources/System/Gravity/GravitySystem.cpp index 8e0801e1..6459ed79 100644 --- a/sources/System/Gravity/GravitySystem.cpp +++ b/sources/System/Gravity/GravitySystem.cpp @@ -16,6 +16,6 @@ namespace BBM auto &position = entity.get(); if (position.getY() > 0) - movable.addForce(Vector3f(0, -0.5, 0)); + movable.addForce(Vector3f(0, -0.1, 0)); } } \ No newline at end of file From 34f9301ac1c14a7c128f694571da55f315751181 Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 10 Jun 2021 14:45:35 +0200 Subject: [PATCH 05/22] Player can't walk on breakable and unbreakable --- sources/Map/Map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 9d76bf45..daab3de5 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -180,7 +180,7 @@ namespace BBM .addComponent(1, &MapGenerator::wallDestroyed) .addComponent( WAL::Callback(), - &MapGenerator::wallCollide, 0.25, .75) + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25), Vector3f(0.75, 1.5, 0.75)) .addComponent(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng)); } @@ -219,7 +219,7 @@ namespace BBM .addComponent>() .addComponent( WAL::Callback(), - &MapGenerator::wallCollide, 0.25, .75) + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25), Vector3f(0.75, 1.5, 0.75)) .addComponent(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePng)); } From 01e5900bbefba5534f502ee5a44af8af0d3fa36a Mon Sep 17 00:00:00 2001 From: Askou Date: Fri, 11 Jun 2021 09:39:31 +0200 Subject: [PATCH 06/22] check in collision if it's a movable --- sources/Map/Map.cpp | 8 ++--- sources/System/Collision/CollisionSystem.cpp | 31 +++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index daab3de5..acc5b671 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -282,7 +282,7 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd > 0.60) { + if (rnd > 0.01) { for (int i = 0; i < width + 1; i++) { map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)]; map[std::make_tuple(i, 0, height)] = UPPERFLOOR; @@ -295,12 +295,10 @@ namespace BBM map[std::make_tuple(width, -1, 1)] = BUMPER; map[std::make_tuple(width / 2, -1, height - 1)] = BUMPER; map[std::make_tuple(width / 2, -1, 1)] = BUMPER; - } - if (rnd > 0.30) { + } + if (rnd > 0.01) { for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { - if (map[std::make_tuple(i, 0, j)] == FLOOR) - continue; map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)]; map[std::make_tuple(i, 0, j)] = UPPERFLOOR; } diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index db68e3c0..ce924797 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -31,23 +31,30 @@ namespace BBM Vector3f pointAx = pointA; Vector3f pointAy = pointA; Vector3f pointAz = pointA; + bool isMovable = false; + Vector3f minAy; + Vector3f maxAy; + Vector3f minAz; + Vector3f maxAz; if (auto *movable = entity->tryGetComponent()) { auto vel = movable->getVelocity(); pointAx.x += vel.x; pointAy.y += vel.y; pointAz.z += vel.z; + isMovable = true; } 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 minAz = Vector3f::min(pointAz, pointAz + colA.bound); - Vector3f maxAz = Vector3f::max(pointAz, pointAz + colA.bound); + if (isMovable) { + 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->getView()) { if (other.getUid() == entity->getUid()) continue; @@ -60,13 +67,15 @@ namespace BBM Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound); if (boxesCollide(minAx, maxAx, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::X; + collidedAxis += isMovable ? CollisionComponent::CollidedAxis::X : 7; } - if (boxesCollide(minAy, maxAy, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Y; - } - if (boxesCollide(minAz, maxAz, minB, maxB)) { - collidedAxis += CollisionComponent::CollidedAxis::Z; + if (isMovable) { + 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)); From 36355f2d78365c746aa4959a55924f17f476e0c8 Mon Sep 17 00:00:00 2001 From: Askou Date: Fri, 11 Jun 2021 11:21:29 +0200 Subject: [PATCH 07/22] only use one collision for each floor instead of each upperfloor block +40fps --- sources/Map/Map.cpp | 55 ++++++++++++++++++++++++++++++++++----- sources/Map/Map.hpp | 9 ++++++- sources/Runner/Runner.cpp | 2 +- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index acc5b671..7381fccc 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -113,7 +113,7 @@ namespace BBM .addComponent>() .addComponent( WAL::Callback(), - &MapGenerator::wallCollide, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallCollide, Vector3f(-(width) / 2 , 0.25, 0.25), Vector3f(width, 2, 0.75)) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -130,7 +130,7 @@ namespace BBM .addComponent(Vector3f(-1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollide, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height - 1)) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); @@ -180,7 +180,7 @@ namespace BBM .addComponent(1, &MapGenerator::wallDestroyed) .addComponent( WAL::Callback(), - &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25), Vector3f(0.75, 1.5, 0.75)) + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25), Vector3f(0.75, 0.75, 0.75)) .addComponent(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng)); } @@ -202,10 +202,10 @@ namespace BBM scene->addEntity("Upper Floor") .addComponent(Vector3f(coords)) - .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)) - .addComponent( + .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); + /*.addComponent( WAL::Callback(), - &MapGenerator::wallCollide, 0.25, 0.75); + &MapGenerator::wallCollide, 0.25, 0.75);*/ } @@ -381,8 +381,49 @@ namespace BBM return (map); } + void MapGenerator::generateHeightCollision(MapBlock map, int width, int height, std::shared_ptr scene) + { + int floor = 2; + + for (int i = 0; i < width + 1; i++) { + if (map[std::make_tuple(i, 1, height)] != UPPERFLOOR && map[std::make_tuple(i, 1, height)] != UPPERFLOOR) { + floor -= 1; + break; + } + } + for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { + for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { + if (map[std::make_tuple(i, 1, i)] != UPPERFLOOR) { + floor -= -1; + break; + } + } + if (floor <= -1) + break; + } + if (floor >= 1) { + scene->addEntity("FloorBot Hitbox") + .addComponent(Vector3f(0, 0, 0)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25), Vector3f(width, 0.75, 0.75)); + scene->addEntity("FloorUp Hitbox") + .addComponent(Vector3f(0, 0, height)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(width, 0.75, 0.75)); + } + if (floor >= 2) + scene->addEntity("Middle Hitbox") + .addComponent(Vector3f(width / 2 - width / 4, 0, height / 2 - height / 4)) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, Vector3f(0.25, 0.25, 0.25),Vector3f(width, 0.75, height / 2 + height / 4)); + } + void MapGenerator::loadMap(int width, int height, MapBlock map, const std::shared_ptr &scene) - { + { + generateHeightCollision(map, width, height, scene); generateWall(width, height, scene); generateFloor(map, width, height, scene); for (int x = 0; x < width + 1; x++) diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 2d7b4a56..f27a1f12 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -28,6 +28,7 @@ namespace BBM class MapGenerator { private: + //! @brief Enum of the block available. enum BlockType { @@ -108,6 +109,13 @@ namespace BBM //! @brief Create upper floor of the map static void createUpperFloor(Vector3f coords, std::shared_ptr scene); + //! @param width Width of the map + //! @param height Height of the map + //! @param scene Scene where the map is instanced + //! @brief Generate the height hitbox of the map + static void generateHeightCollision(MapBlock map, int width, int height, + std::shared_ptr scene); + //! @param map Map to load with block declared inside //! @param width Width of the map //! @param height Height of the map @@ -180,6 +188,5 @@ namespace BBM //! @param scene Scene where the map is instanced //! @brief Generate the map static void loadMap(int width, int height, MapBlock map, const std::shared_ptr &scene); - }; } // namespace BBM \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 5cdcbd3a..1425748c 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -115,7 +115,7 @@ namespace BBM animation.setAnimIndex(5); }); scene->addEntity("camera") - .addComponent(8, 20, 7) + .addComponent(8, 25, 7) .addComponent(Vector3f(8, 0, 8)); /*scene->addEntity("cube") .addComponent(5, 0, 5) From 73b8cc5ccd4a4a7905c958fdf74ed6d647a52cd0 Mon Sep 17 00:00:00 2001 From: Askou Date: Fri, 11 Jun 2021 19:25:43 +0200 Subject: [PATCH 08/22] fix floor hitbox on no floor map --- sources/Map/Map.cpp | 9 +++++---- sources/Map/Map.hpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index af76ec99..f158d81b 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -381,7 +381,7 @@ namespace BBM return (map); } - MapGenerator::MapBlock MapGenerator::createMap(int width, int height) + MapGenerator::MapBlock MapGenerator::createMap(int width, int height, bool isHeight) { MapBlock map; @@ -408,7 +408,8 @@ namespace BBM for (int j = 0; j < height + 1; j++) if (!((i + 1) % 2) && !((j + 1) % 2)) map[std::make_tuple(i, 0, j)] = UNBREAKABLE; - map = createHeight(map, width, height); + if (isHeight) + map = createHeight(map, width, height); map = cleanBreakable(map, width, height); return (map); } @@ -426,11 +427,11 @@ namespace BBM for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { if (map[std::make_tuple(i, 1, i)] != UPPERFLOOR) { - floor -= -1; + floor -= 1; break; } } - if (floor <= -1) + if (floor <= 0) break; } if (floor >= 1) { diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 8161364d..562bfb40 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -181,7 +181,7 @@ namespace BBM //! @param width Width of the map //! @param height Height of the map //! @brief Generate map of block to be loaded - static MapBlock createMap(int width, int height); + static MapBlock createMap(int width, int height, bool isHeight = false); //! @param width Width of the map //! @param height Height of the map From a9edacd41bdb95073591dc8c3d2986f269ecb8f7 Mon Sep 17 00:00:00 2001 From: Askou Date: Fri, 11 Jun 2021 19:27:02 +0200 Subject: [PATCH 09/22] remove debug print in bombHolderSystem --- sources/System/BombHolder/BombHolderSystem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 4a582b26..a6993e36 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, posFrom](WAL::Wal &wal) { for (auto &[entity, pos, _] : wal.getScene()->view>()) { if (pos.position.round() == position) { From fd391d869e500cf91ff6e6adefdeab2e84c0de60 Mon Sep 17 00:00:00 2001 From: Askou Date: Sat, 12 Jun 2021 11:09:24 +0200 Subject: [PATCH 10/22] remove ugly 20lines createSpawner --- sources/Map/Map.cpp | 45 ++++++++++++++++++++++++--------------------- sources/Map/Map.hpp | 14 +++++++++++++- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index f158d81b..8b5d8206 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -346,25 +346,9 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height) { map[std::make_tuple(0, 0, 0)] = SPAWNER; - map[std::make_tuple(0, 0, 1)] = SPAWNER; - map[std::make_tuple(0, 0, 2)] = SPAWNER; - map[std::make_tuple(1, 0, 0)] = SPAWNER; - map[std::make_tuple(2, 0, 0)] = SPAWNER; map[std::make_tuple(width, 0, 0)] = SPAWNER; - map[std::make_tuple(width - 1, 0, 0)] = SPAWNER; - map[std::make_tuple(width - 2, 0, 0)] = SPAWNER; - map[std::make_tuple(width, 0, 1)] = SPAWNER; - map[std::make_tuple(width, 0, 2)] = SPAWNER; map[std::make_tuple(0, 0, height)] = SPAWNER; - map[std::make_tuple(1, 0, height)] = SPAWNER; - map[std::make_tuple(2, 0, height)] = SPAWNER; - map[std::make_tuple(0, 0, height - 1)] = SPAWNER; - map[std::make_tuple(0, 0, height - 2)] = SPAWNER; map[std::make_tuple(width, 0, height)] = SPAWNER; - map[std::make_tuple(width, 0, height - 1)] = SPAWNER; - map[std::make_tuple(width, 0, height - 2)] = SPAWNER; - map[std::make_tuple(width - 1, 0, height)] = SPAWNER; - map[std::make_tuple(width - 2, 0, height)] = SPAWNER; return map; } @@ -381,7 +365,26 @@ namespace BBM return (map); } - MapGenerator::MapBlock MapGenerator::createMap(int width, int height, bool isHeight) + MapGenerator::MapBlock MapGenerator::createClassicUnbreakable(MapBlock map, int width, int height) + { + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height + 1; j++) + if (!((i + 1) % 2) && !((j + 1) % 2)) + map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + return (map); + } + + MapGenerator::MapBlock MapGenerator::createLongClassicUnbreakable(MapBlock map, int width, int height) + { + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height + 1; j++) + if ((i % 3) && !((j + 1) % 2)) + map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + return (map); + } + + + MapGenerator::MapBlock MapGenerator::createMap(int width, int height, bool isHeight, bool isNotClassic) { MapBlock map; @@ -404,10 +407,10 @@ namespace BBM map[std::make_tuple(i, 0, j)] = BREAKABLE; } } - for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) - if (!((i + 1) % 2) && !((j + 1) % 2)) - map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + if (!isNotClassic) + map = createClassicUnbreakable(map, width, height); + else + map = createLongClassicUnbreakable(map, width, height); if (isHeight) map = createHeight(map, width, height); map = cleanBreakable(map, width, height); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 562bfb40..f7eef37c 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -119,6 +119,18 @@ namespace BBM static void generateHeightCollision(MapBlock map, int width, int height, std::shared_ptr scene); + //! @param map Map to load with block declared inside + //! @param width Width of the map + //! @param height Height of the map + //! @brief Generate unbreakable block on the map + static MapBlock createClassicUnbreakable(MapBlock map, int width, int height); + + //! @param map Map to load with block declared inside + //! @param width Width of the map + //! @param height Height of the map + //! @brief Generate unbreakable block on map + static MapBlock createLongClassicUnbreakable(MapBlock map, int width, int height); + //! @param map Map to load with block declared inside //! @param width Width of the map //! @param height Height of the map @@ -181,7 +193,7 @@ namespace BBM //! @param width Width of the map //! @param height Height of the map //! @brief Generate map of block to be loaded - static MapBlock createMap(int width, int height, bool isHeight = false); + static MapBlock createMap(int width, int height, bool isHeight = false, bool isNotClassic = false); //! @param width Width of the map //! @param height Height of the map From 230b611b698830e5396dcc28d9c3dbe56cef199d Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 10:01:56 +0200 Subject: [PATCH 11/22] Add another flat map type --- sources/Map/Map.cpp | 21 +++++++++++++++------ sources/Runner/Runner.cpp | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 8b5d8206..90de3fec 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -303,10 +303,10 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd > 0.95) + if (rnd > 0.98) return HOLE; if (rnd > 0.25) - return BREAKABLE; + return NOTHING; return NOTHING; } @@ -376,10 +376,19 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createLongClassicUnbreakable(MapBlock map, int width, int height) { - for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) - if ((i % 3) && !((j + 1) % 2)) + int placedSpace = 0; + + for (int i = 1; i < width; i++) { + placedSpace = 0; + for (int j = 1; j < height; j++) { + if (!(j % 2)) + continue; + if (i < (width / 2 - width / 10) || i > (width / 2 + width / 10)) map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + else + placedSpace++; + } + } return (map); } @@ -399,7 +408,7 @@ namespace BBM if (map[std::make_tuple(i, 0, j)] == SPAWNER) continue; if (isCloseToBlockType(map, i, 0, j, SPAWNER)) { - map[std::make_tuple(i, 0, j)] = NOTHING; + map[std::make_tuple(i, isNotClassic ? -1 : 0, j)] = isNotClassic ? BUMPER : NOTHING; } else { map[std::make_tuple(i, 0, j)] = getRandomBlockType(); } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 613b6a58..687fcc1d 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -551,7 +551,7 @@ namespace BBM scene->addEntity("camera") .addComponent(8, 25, 7) .addComponent(Vector3f(8, 0, 8)); - MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); + MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, false, true), scene); return scene; } From d3f77835d34e9b611ad77faaccef7d3403f18e7b Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 10:51:49 +0200 Subject: [PATCH 12/22] fix cmake not compiling because of git merge --- .../System/BombHolder/BombHolderSystem.cpp | 28 ++++++------------- .../System/BombHolder/BombHolderSystem.hpp | 9 ++---- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 1cae7500..d91c2a27 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -31,13 +31,14 @@ namespace BBM return MapGenerator::wallCollided( entity, bomb, collidedAxis); } + BombHolderSystem::BombHolderSystem(WAL::Wal &wal) : System(wal) {} - void BombHolderSystem::_dispatchExplosion(const Vector3f &position, WAL::Wal &wal, int radiusToDo, const Vector3f &posFrom) + void BombHolderSystem::_dispatchExplosion(Vector3f position, WAL::Wal &wal, int count) { - if (radiusToDo <= 0) + if (count <= 0) return; wal.getScene()->scheduleNewEntity("explosion") .addComponent(position) @@ -54,23 +55,10 @@ 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); - } + _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); }); } @@ -79,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, 3 + (explosionRadius - 3)); } 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..6d26435e 100644 --- a/sources/System/BombHolder/BombHolderSystem.hpp +++ b/sources/System/BombHolder/BombHolderSystem.hpp @@ -22,12 +22,7 @@ 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); - - //! @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); - }; + static void _dispatchExplosion(Vector3f position, WAL::Wal &, int count); //! @brief The method triggered when the bomb explode. static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &); @@ -51,4 +46,4 @@ namespace BBM //! @brief A bomb holder system is not assignable. BombHolderSystem &operator=(const BombHolderSystem &) = delete; }; -} +} \ No newline at end of file From 993aadcf6c82b9399348eb3c9d0c4bdb0c0e10c7 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 11:27:49 +0200 Subject: [PATCH 13/22] put classic mode --- sources/Runner/Runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 687fcc1d..f8a44bb4 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -551,7 +551,7 @@ namespace BBM scene->addEntity("camera") .addComponent(8, 25, 7) .addComponent(Vector3f(8, 0, 8)); - MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, false, true), scene); + MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, false, false), scene); return scene; } From 669c17ae24cfa998b2e72db1087fe6fbef352172 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 11:38:06 +0200 Subject: [PATCH 14/22] fix comment --- sources/Component/BumperTimer/BumperTimerComponent.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Component/BumperTimer/BumperTimerComponent.hpp b/sources/Component/BumperTimer/BumperTimerComponent.hpp index dbeba275..a0b8c958 100644 --- a/sources/Component/BumperTimer/BumperTimerComponent.hpp +++ b/sources/Component/BumperTimer/BumperTimerComponent.hpp @@ -18,9 +18,9 @@ namespace BBM bool _isReseting = false; - //! @brief The number of seconds of each refill. This variable is used to reset the nextBombRefill value. + //! @brief The number of seconds of each rest. This variable is used to reset the nextReset value. std::chrono::nanoseconds resetRate = 1500ms; - //! @brief The number of nanosecond before the next bomb refill. + //! @brief The number of nanosecond before the next bumper reset for the player. std::chrono::nanoseconds nextReset = resetRate; //! @inherit From 7a21b8ed9466e76cfc4ef6b806a745212195aec6 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 14:27:52 +0200 Subject: [PATCH 15/22] add brackets for clarification --- sources/Map/Map.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index db57c953..c188bcdd 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -381,10 +381,12 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createClassicUnbreakable(MapBlock map, int width, int height) { - for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) + for (int i = 0; i < width + 1; i++) { + for (int j = 0; j < height + 1; j++) { if (!((i + 1) % 2) && !((j + 1) % 2)) map[std::make_tuple(i, 0, j)] = UNBREAKABLE; + } + } return (map); } From 2260f8ba4f862e68bb15c95ea8c03fad32a91cd9 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 15:13:45 +0200 Subject: [PATCH 16/22] set full heigth map at -1 to check if their height --- sources/Map/Map.cpp | 8 ++++++-- sources/Runner/Runner.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index c188bcdd..4313ee7c 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -328,6 +328,9 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height + 1; j++) + map[std::make_tuple(i, 1, j)] == -1; if (rnd > 0.01) { for (int i = 0; i < width + 1; i++) { map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)]; @@ -447,14 +450,14 @@ namespace BBM int floor = 2; for (int i = 0; i < width + 1; i++) { - if (map[std::make_tuple(i, 1, height)] != UPPERFLOOR && map[std::make_tuple(i, 1, height)] != UPPERFLOOR) { + if (map[std::make_tuple(i, 1, height)] == -1) { floor -= 1; break; } } for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { - if (map[std::make_tuple(i, 1, i)] != UPPERFLOOR) { + if (map[std::make_tuple(i, 1, i)] == -1) { floor -= 1; break; } @@ -462,6 +465,7 @@ namespace BBM if (floor <= 0) break; } + std::cout << floor << std::endl; if (floor >= 1) { scene->addEntity("FloorBot Hitbox") .addComponent(Vector3f(0, 0, 0)) diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index f8a44bb4..a981c9a2 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -551,7 +551,7 @@ namespace BBM scene->addEntity("camera") .addComponent(8, 25, 7) .addComponent(Vector3f(8, 0, 8)); - MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, false, false), scene); + MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16, true, false), scene); return scene; } From b7149a7a7a54af731eb0463b0512d2e26b485c7d Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 15:15:19 +0200 Subject: [PATCH 17/22] replace NOTHING by BREAKABLE in getRandomBlockType() --- sources/Map/Map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 4313ee7c..1d612970 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -320,7 +320,7 @@ namespace BBM if (rnd > 0.98) return HOLE; if (rnd > 0.25) - return NOTHING; + return BREAKABLE; return NOTHING; } From 85dcf80256056ae776cc230e07738636a7397157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 16:45:43 +0200 Subject: [PATCH 18/22] fixing player pos and rm debug print --- sources/Map/Map.cpp | 1 - sources/Runner/GameScene.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index b206a330..9bdb3160 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -467,7 +467,6 @@ namespace BBM if (floor <= 0) break; } - std::cout << floor << std::endl; if (floor >= 1) { scene->addEntity("FloorBot Hitbox") .addComponent(Vector3f(0, 0, 0)) diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 1cf2299d..7668a043 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -42,7 +42,7 @@ namespace BBM //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; scene->addEntity("player") - .addComponent() + .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() From 4fb31b459819fd3ef24122f4eaee0790ad722e62 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 17:02:05 +0200 Subject: [PATCH 19/22] fix collision on invisible height --- sources/Map/Map.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 1d612970..9af4cc26 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -328,9 +328,6 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; - for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) - map[std::make_tuple(i, 1, j)] == -1; if (rnd > 0.01) { for (int i = 0; i < width + 1; i++) { map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)]; @@ -421,6 +418,9 @@ namespace BBM for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) map[std::make_tuple(i, 0, j)] = NOTHING; + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height + 1; j++) + map[std::make_tuple(i, 1, j)] == -1; map = createSpawner(map, width, height); for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; j++) { @@ -450,7 +450,7 @@ namespace BBM int floor = 2; for (int i = 0; i < width + 1; i++) { - if (map[std::make_tuple(i, 1, height)] == -1) { + if (map[std::make_tuple(i, 1, height)] == -1 && map[std::make_tuple(i, 1, 0)] == -1) { floor -= 1; break; } @@ -465,7 +465,6 @@ namespace BBM if (floor <= 0) break; } - std::cout << floor << std::endl; if (floor >= 1) { scene->addEntity("FloorBot Hitbox") .addComponent(Vector3f(0, 0, 0)) From 34eeb13286b2303ccf351b6be8414a7301efe1ce Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 17:15:34 +0200 Subject: [PATCH 20/22] Look at the correct block when we need to place collision for floor --- sources/Map/Map.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 85967077..528151e9 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -9,7 +9,6 @@ #include #include #include -#include "Component/Movable/MovableComponent.hpp" #include #include #include @@ -82,7 +81,6 @@ namespace BBM wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) .addComponent>() - .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); }) @@ -195,7 +193,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("Floor") + scene->addEntity("Unbreakable Wall") .addComponent(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); @@ -417,12 +415,11 @@ namespace BBM width = width % 2 ? width + 1 : width; height = height % 2 ? height + 1 : height; - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - map[std::make_tuple(i, 0, j)] = NOTHING; for (int i = 0; i < width + 1; i++) - for (int j = 0; j < height + 1; j++) - map[std::make_tuple(i, 1, j)] == -1; + for (int j = 0; j < height + 1; j++) { + map[std::make_tuple(i, 0, j)] = NOTHING; + map[std::make_tuple(i, 1, j)] = NOTHING; + } map = createSpawner(map, width, height); for (int i = 0; i < width + 1; i++) { for (int j = 0; j < height + 1; j++) { @@ -452,14 +449,14 @@ namespace BBM int floor = 2; for (int i = 0; i < width + 1; i++) { - if (map[std::make_tuple(i, 1, height)] == -1 && map[std::make_tuple(i, 1, 0)] == -1) { + if (map[std::make_tuple(i, 0, height)] == NOTHING && map[std::make_tuple(i, 0, 0)] == NOTHING) { floor -= 1; break; } } for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) { for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) { - if (map[std::make_tuple(i, 1, i)] == -1) { + if (map[std::make_tuple(i, 0, i)] == NOTHING) { floor -= 1; break; } From 7760f97b5a6ed46376adfc4af05d8412522c41c0 Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 17:25:34 +0200 Subject: [PATCH 21/22] Rename ground entity --- sources/Map/Map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 528151e9..2e128bde 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -193,7 +193,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("Ground") .addComponent(Vector3f(i, -1, j)) .addComponent(floorObj, false, std::make_pair(MAP_DIFFUSE, floorPng)); From 3eaa27003c20f16179c4f6a60998a788797e1147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 14 Jun 2021 17:26:17 +0200 Subject: [PATCH 22/22] readding Movable component of bonuses --- sources/Map/Map.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 528151e9..d43b5c81 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -81,6 +81,7 @@ namespace BBM wal.getScene()->scheduleNewEntity("Bonus") .addComponent(position) .addComponent>() + .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); })