From d08613a9d41192d2c61fb9c34caba304ccdd6e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 8 Jun 2021 11:58:30 +0200 Subject: [PATCH] zoe has to smile ! --- .../Collision/CollisionComponent.cpp | 8 +- .../Collision/CollisionComponent.hpp | 12 +- sources/Map/Map.cpp | 46 +++- sources/Map/Map.hpp | 251 +++++++++--------- sources/System/Collision/CollisionSystem.cpp | 4 +- 5 files changed, 172 insertions(+), 149 deletions(-) diff --git a/sources/Component/Collision/CollisionComponent.cpp b/sources/Component/Collision/CollisionComponent.cpp index 678b0898..652e6727 100644 --- a/sources/Component/Collision/CollisionComponent.cpp +++ b/sources/Component/Collision/CollisionComponent.cpp @@ -16,8 +16,8 @@ namespace BBM } CollisionComponent::CollisionComponent(WAL::Entity &entity, - const WAL::Callback &onCollide, - const WAL::Callback &onCollided, + const WAL::Callback &onCollide, + const WAL::Callback &onCollided, Vector3f positionOffset, Vector3f bound) : WAL::Component(entity), @@ -28,8 +28,8 @@ namespace BBM {} CollisionComponent::CollisionComponent(WAL::Entity &entity, - const WAL::Callback &onCollide, - const WAL::Callback &onCollided, + const WAL::Callback &onCollide, + const WAL::Callback &onCollided, float positionOffset, float boundSize) : WAL::Component(entity), diff --git a/sources/Component/Collision/CollisionComponent.hpp b/sources/Component/Collision/CollisionComponent.hpp index 02eaf4b9..06878a76 100644 --- a/sources/Component/Collision/CollisionComponent.hpp +++ b/sources/Component/Collision/CollisionComponent.hpp @@ -23,9 +23,9 @@ namespace BBM }; //! @brief onCollide functions to be called - WAL::Callback onCollide; + WAL::Callback onCollide; //! @brief onCollided functions to be called - WAL::Callback onCollided; + WAL::Callback onCollided; //! @brief Bound size on all axis Vector3f bound; //! @brief Offset from the position component @@ -39,15 +39,15 @@ namespace BBM //! @brief Constructor with a WAL::Callback CollisionComponent(WAL::Entity &entity, - const WAL::Callback &onCollide, - const WAL::Callback &onCollided, + const WAL::Callback &onCollide, + const WAL::Callback &onCollided, Vector3f positionOffset, Vector3f bound); //! @brief Constructor with a WAL::Callback, same boundSize for all axis CollisionComponent(WAL::Entity &entity, - const WAL::Callback &onCollide, - const WAL::Callback &onCollided, + const WAL::Callback &onCollide, + const WAL::Callback &onCollided, float positionOffset, float boundSize); diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index ad5b2f09..1fd5b0bc 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -12,7 +12,9 @@ namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { - void MapGenerator::wallCollide(WAL::Entity &entity, const WAL::Entity &wall, int collidedAxis) + void MapGenerator::wallCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) { auto *mov = entity.tryGetComponent(); @@ -49,8 +51,11 @@ namespace BBM if (!(i % 2) && !(j % 2)) { scene->addEntity("Unbreakable Wall") .addComponent(i, 0, j) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) - .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePng)); + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) + .addComponent(unbreakableObj, + std::make_pair(MAP_DIFFUSE, unbreakablePng)); } } } @@ -63,25 +68,33 @@ namespace BBM scene->addEntity("Bottom Wall") .addComponent(Vector3f((width + 1) / 2, 0, -1)) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); scene->addEntity("Upper Wall") .addComponent(Vector3f((width + 1) / 2, 0, height + 1)) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); scene->addEntity("Left Wall") .addComponent(Vector3f(width + 1, 0, height / 2)) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); scene->addEntity("Right Wall") .addComponent(Vector3f(-1, 0, height / 2)) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); @@ -97,7 +110,7 @@ namespace BBM if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER) scene->addEntity("Unbreakable Wall") .addComponent(Vector3f(i, -1, j)) - .addComponent(floorObj, + .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); } } @@ -131,7 +144,9 @@ namespace BBM scene->addEntity("Breakable Block") .addComponent(coords) .addComponent(1) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng)); } @@ -142,7 +157,7 @@ namespace BBM scene->addEntity("Floor") .addComponent(Vector3f(coords)) - //.addComponent(1) + //.addComponent(1) .addComponent(floorObj, std::make_pair(MAP_DIFFUSE, floorPng)); } @@ -164,7 +179,9 @@ namespace BBM scene->addEntity("Unbreakable Block") .addComponent(coords) - .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 0.25, .75) + .addComponent( + WAL::Callback(), + &MapGenerator::wallCollide, 0.25, .75) .addComponent(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePng)); } @@ -183,7 +200,8 @@ namespace BBM if (coords.y == 0) holeEntity.addComponent(holeObj, std::make_pair(MAP_DIFFUSE, holePng)); else - holeEntity.addComponent(secondFloorObj, std::make_pair(MAP_DIFFUSE, secondFloorPng)); + holeEntity.addComponent(secondFloorObj, + std::make_pair(MAP_DIFFUSE, secondFloorPng)); /*.addComponent([](WAL::Entity &other, const WAL::Entity &entity) { if (other.hasComponent()) { auto &health = other.getComponent(); @@ -215,7 +233,7 @@ namespace BBM scene->addEntity("Stairs Block") .addComponent(coords) - //.addComponent(1) + //.addComponent(1) .addComponent(stairsObj, std::make_pair(MAP_DIFFUSE, stairsPng)); } @@ -328,7 +346,7 @@ namespace BBM return (map); } - void MapGenerator::loadMap(int width, int height, MapBlock map, std::shared_ptr scene) + void MapGenerator::loadMap(int width, int height, MapBlock map, const std::shared_ptr &scene) { generateWall(width, height, scene); generateFloor(map, width, height, scene); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index f705eebf..82af402a 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -27,149 +27,154 @@ namespace BBM class MapGenerator { - private: - //! @brief Enum of the block available. - enum BlockType { - NOTHING, - BREAKABLE, - HOLE, - UPPERFLOOR, - FLOOR, - BUMPER, - STAIRS, - SPAWNER, - UNBREAKABLE - }; + private: + //! @brief Enum of the block available. + enum BlockType + { + NOTHING, + BREAKABLE, + HOLE, + UPPERFLOOR, + FLOOR, + BUMPER, + STAIRS, + SPAWNER, + UNBREAKABLE + }; - using MapElem = std::function scene)>; - using MapBlock = std::map, BlockType>; + using MapElem = std::function scene)>; + using MapBlock = std::map, BlockType>; - //! @brief Generate random block type - static BlockType getRandomBlockType(); + //! @brief Generate random block type + static BlockType getRandomBlockType(); - //! @param map ASCII map - //! @param x x index on the block - //! @param z z index on the block - //! @param blockType blockType to compare with position - static bool isCloseToBlockType(std::map, BlockType> map, int x, int y, int z, BlockType blockType); + //! @param map ASCII map + //! @param x x index on the block + //! @param z z index on the block + //! @param blockType blockType to compare with position + static bool isCloseToBlockType(std::map, BlockType> map, + int x, int y, int z, + BlockType blockType); - //! @param width Width of the map - //! @param height Height of the map - //! @param scene Scene where the map is instanced - //! @brief Generate the unbreakable block of the map - static void generateUnbreakableBlock(int width, int height, 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 unbreakable block of the map + static void generateUnbreakableBlock(int width, int height, 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 wall of the map - static void generateWall(int width, int height, 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 wall of the map + static void generateWall(int width, int height, 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 floor of the map - static void generateFloor(MapBlock map, int width, int height, 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 floor of the map + static void generateFloor(MapBlock map, int width, int height, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create element of the map - static void createElement(Vector3f coords, std::shared_ptr scene, BlockType blockType); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create element of the map + static void createElement(Vector3f coords, std::shared_ptr scene, BlockType blockType); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create breakable of the map - static void createBreakable(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create breakable of the map + static void createBreakable(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create unbreakable of the map - static void createUnbreakable(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create unbreakable of the map + static void createUnbreakable(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create hole of the map - static void createHole(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create hole of the map + static void createHole(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create bumper of the map - static void createBumper(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create bumper of the map + static void createBumper(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create floor of the map - static void createFloor(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create floor of the map + static void createFloor(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create upper floor of the map - static void createUpperFloor(Vector3f coords, std::shared_ptr scene); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create upper floor of the map + static void createUpperFloor(Vector3f coords, std::shared_ptr scene); - //! @param coords coords of the element - //! @param scene Scene where the map is instanced - //! @brief Create stair of the map - static void createStairs(Vector3f coords, 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 map of block to be loaded - static MapBlock createSpawner(MapBlock map, int width, int height); + //! @param coords coords of the element + //! @param scene Scene where the map is instanced + //! @brief Create stair of the map + static void createStairs(Vector3f coords, 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 height for the map - static MapBlock createHeight(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 map of block to be loaded + static MapBlock createSpawner(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 Clean breakable on stairs, bumpers, etc.. - static MapBlock cleanBreakable(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 height for the map + static MapBlock createHeight(MapBlock map, int width, int height); - - static const std::string assetsPath; - - static const std::string wallAssetsPath; - - static const std::string imageExtension; - - static const std::string objExtension; - - static const std::string unbreakableWallPath; - - static const std::string breakableWallPath; - - static const std::string floorPath; - - static const std::string stairsPath; - - static const std::string bumperPath; - - static const std::string secondFloorPath; - - static const std::string holePath; - - static const std::string secondFloorHolePath; - - public: - static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall, int collidedAxis); + //! @param map Map to load with block declared inside + //! @param width Width of the map + //! @param height Height of the map + //! @brief Clean breakable on stairs, bumpers, etc.. + static MapBlock cleanBreakable(MapBlock map, int width, int height); - //! @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 const std::string assetsPath; + + static const std::string wallAssetsPath; + + static const std::string imageExtension; + + static const std::string objExtension; + + static const std::string unbreakableWallPath; + + static const std::string breakableWallPath; + + static const std::string floorPath; + + static const std::string stairsPath; + + static const std::string bumperPath; + + static const std::string secondFloorPath; + + static const std::string holePath; + + static const std::string secondFloorHolePath; + + public: + static void wallCollide(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); + + + //! @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); + + //! @param width Width of the map + //! @param height Height of the map + //! @param map Map to load with block declared inside + //! @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); - //! @param width Width of the map - //! @param height Height of the map - //! @param map Map to load with block declared inside - //! @param scene Scene where the map is instanced - //! @brief Generate the map - static void loadMap(int width, int height, MapBlock map, std::shared_ptr scene); - }; } // namespace BBM \ No newline at end of file diff --git a/sources/System/Collision/CollisionSystem.cpp b/sources/System/Collision/CollisionSystem.cpp index c45f3ca1..db68e3c0 100644 --- a/sources/System/Collision/CollisionSystem.cpp +++ b/sources/System/Collision/CollisionSystem.cpp @@ -69,8 +69,8 @@ namespace BBM collidedAxis += CollisionComponent::CollidedAxis::Z; } if (collidedAxis) { - colA.onCollide(entity, other, collidedAxis); - colB.onCollided(entity, other, collidedAxis); + colA.onCollide(entity, other, static_cast(collidedAxis)); + colB.onCollided(entity, other, static_cast(collidedAxis)); } } }