diff --git a/assets/wall/test.mtl b/assets/wall/test.mtl new file mode 100644 index 00000000..86d5a0cf --- /dev/null +++ b/assets/wall/test.mtl @@ -0,0 +1,54 @@ +# Blender v2.92.0 OBJ File: '' +# www.blender.org +mtllib breakable_wall.mtl +o cube +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v -0.500000 0.500000 -0.500000 +v 0.500000 0.500000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +vt 0.000000 0.000000 +vt 0.333333 0.000000 +vt 0.000000 0.500000 +vt 0.333333 0.500000 +vt 0.666666 1.000000 +vt 1.000000 1.000000 +vt 0.666666 0.500000 +vt 1.000000 0.500000 +vt 0.000000 1.000000 +vt 0.333333 1.000000 +vt 0.000000 0.500000 +vt 0.333333 0.500000 +vt 0.666666 0.000000 +vt 1.000000 0.000000 +vt 0.666666 0.500000 +vt 1.000000 0.500000 +vt 0.666666 0.500000 +vt 0.666666 1.000000 +vt 0.333333 0.000000 +vt 0.666666 0.000000 +vt 0.333333 0.500000 +vt 0.666666 0.500000 +vn 0.0000 -0.0000 1.0000 +vn 0.0000 1.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +vn 0.0000 -1.0000 -0.0000 +vn 1.0000 0.0000 0.0000 +vn -1.0000 0.0000 0.0000 +usemtl cube +s 1 +f 1/1/1 2/2/1 3/3/1 +f 3/3/1 2/2/1 4/4/1 +f 3/5/2 4/6/2 5/7/2 +f 5/7/2 4/6/2 6/8/2 +f 5/9/3 6/10/3 7/11/3 +f 7/11/3 6/10/3 8/12/3 +f 7/13/4 8/14/4 1/15/4 +f 1/15/4 8/14/4 2/16/4 +f 2/17/5 8/12/5 4/18/5 +f 4/18/5 8/12/5 6/10/5 +f 7/19/6 1/20/6 5/21/6 +f 5/21/6 1/20/6 3/22/6 diff --git a/assets/wall/test.obj b/assets/wall/test.obj new file mode 100644 index 00000000..144c9997 --- /dev/null +++ b/assets/wall/test.obj @@ -0,0 +1,61 @@ +# floor.obj +# + +mtllib floor.mtl +o floor + +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v -0.500000 0.500000 -0.500000 +v 0.500000 0.500000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 + +vt 0.000000 0.000000 +vt 0.333333 0.000000 +vt 0.666666 0.000000 +vt 1.000000 0.000000 +vt 0.000000 0.500000 +vt 0.333333 0.500000 +vt 0.666666 0.500000 +vt 1.000000 0.500000 +vt 0.000000 1.000000 +vt 0.333333 1.000000 +vt 0.666666 1.000000 +vt 1.000000 1.000000 + +vn 0.000000 0.000000 1.000000 +vn 0.000000 1.000000 0.000000 +vn 0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 0.000000 +vn 1.000000 0.000000 0.000000 +vn -1.000000 0.000000 0.000000 + +g floor +usemtl floor +# Back +s 1 +f 1/1/1 2/4/1 3/9/1 +f 3/9/1 2/4/1 4/12/1 +# Top +s 2 +f 3/1/2 4/4/2 5/9/2 +f 5/9/2 4/4/2 6/12/2 +# Front +s 3 +f 5/1/3 6/4/3 7/9/3 +f 7/9/3 6/4/3 8/12/3 +# Bottom +s 4 +f 7/1/4 8/4/4 1/9/4 +f 1/9/4 8/4/4 2/12/4 +# Right +s 5 +f 2/1/5 8/4/5 4/9/5 +f 4/9/5 8/4/5 6/12/5 +# Left +s 6 +f 7/1/6 1/4/6 5/9/6 +f 5/9/6 1/4/6 3/12/6 \ No newline at end of file diff --git a/assets/wall/test.png b/assets/wall/test.png new file mode 100644 index 00000000..bdbc5fda Binary files /dev/null and b/assets/wall/test.png differ diff --git a/assets/wall/upper_floor.mtl b/assets/wall/upper_floor.mtl new file mode 100644 index 00000000..7925a729 --- /dev/null +++ b/assets/wall/upper_floor.mtl @@ -0,0 +1,12 @@ +# Blender MTL File: 'None' +# Material Count: 1 + +newmtl Cube.001 +Ns 225.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 2 diff --git a/assets/wall/upper_floor.obj b/assets/wall/upper_floor.obj new file mode 100644 index 00000000..144c9997 --- /dev/null +++ b/assets/wall/upper_floor.obj @@ -0,0 +1,61 @@ +# floor.obj +# + +mtllib floor.mtl +o floor + +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v -0.500000 0.500000 -0.500000 +v 0.500000 0.500000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 + +vt 0.000000 0.000000 +vt 0.333333 0.000000 +vt 0.666666 0.000000 +vt 1.000000 0.000000 +vt 0.000000 0.500000 +vt 0.333333 0.500000 +vt 0.666666 0.500000 +vt 1.000000 0.500000 +vt 0.000000 1.000000 +vt 0.333333 1.000000 +vt 0.666666 1.000000 +vt 1.000000 1.000000 + +vn 0.000000 0.000000 1.000000 +vn 0.000000 1.000000 0.000000 +vn 0.000000 0.000000 -1.000000 +vn 0.000000 -1.000000 0.000000 +vn 1.000000 0.000000 0.000000 +vn -1.000000 0.000000 0.000000 + +g floor +usemtl floor +# Back +s 1 +f 1/1/1 2/4/1 3/9/1 +f 3/9/1 2/4/1 4/12/1 +# Top +s 2 +f 3/1/2 4/4/2 5/9/2 +f 5/9/2 4/4/2 6/12/2 +# Front +s 3 +f 5/1/3 6/4/3 7/9/3 +f 7/9/3 6/4/3 8/12/3 +# Bottom +s 4 +f 7/1/4 8/4/4 1/9/4 +f 1/9/4 8/4/4 2/12/4 +# Right +s 5 +f 2/1/5 8/4/5 4/9/5 +f 4/9/5 8/4/5 6/12/5 +# Left +s 6 +f 7/1/6 1/4/6 5/9/6 +f 5/9/6 1/4/6 3/12/6 \ No newline at end of file diff --git a/assets/wall/upper_floor.png b/assets/wall/upper_floor.png new file mode 100644 index 00000000..e31c7154 Binary files /dev/null and b/assets/wall/upper_floor.png differ diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index ae546adb..819c99e4 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -19,7 +19,7 @@ namespace BBM if (!(i % 2) && !(j % 2)) { scene->addEntity("Unbreakable Wall") .addComponent(Vector3f(i, 0, j)) - .addComponent(1) + //.addComponent(1) .addComponent>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj)); } } @@ -33,19 +33,19 @@ namespace BBM scene->addEntity("Bottom Wall") .addComponent(Vector3f((width + 1) / 2, 0, -1)) - .addComponent(1) + //.addComponent(1) .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(1) + //.addComponent(1) .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(1) + //.addComponent(1) .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(1) + //.addComponent(1) .addComponent>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj), RAY::Vector3(1, 1, height + 1)); } @@ -56,7 +56,7 @@ namespace BBM if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, 0, j)] != BUMPER) scene->addEntity("Unbreakable Wall") .addComponent(Vector3f(i, -1, j)) - .addComponent(1) + //.addComponent(1) .addComponent>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png")); } } @@ -70,7 +70,8 @@ namespace BBM {HOLE, &createHole}, {FLOOR, &createFloor}, {BUMPER, &createBumper}, - {STAIRS, &createStairs} + {STAIRS, &createStairs}, + {UPPERFLOOR, &createUpperFloor}, }; try { @@ -86,23 +87,32 @@ namespace BBM scene->addEntity("Breakable Block") .addComponent(coords) .addComponent(1) - .addComponent(1) - .addComponent>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png")); + //.addComponent(1) + .addComponent>("assets/wall/breakatble_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png")); } void MapGenerator::createFloor(Vector3f coords, std::shared_ptr scene) { scene->addEntity("Floor") .addComponent(Vector3f(coords)) - .addComponent(1) + //.addComponent(1) .addComponent>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png")); } + void MapGenerator::createUpperFloor(Vector3f coords, std::shared_ptr scene) + { + scene->addEntity("Upper Floor") + .addComponent(Vector3f(coords)) + //.addComponent(1) + .addComponent>("assets/wall/upper_floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/upper_floor.png")); + } + + void MapGenerator::createUnbreakable(Vector3f coords, std::shared_ptr scene) { scene->addEntity("Unbreakable Block") .addComponent(coords) - .addComponent(1) + //.addComponent(1) .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); } @@ -110,27 +120,27 @@ namespace BBM { scene->addEntity("Hole Block") .addComponent(Vector3f(coords.x, coords.y - 1, coords.z)) - .addComponent>("assets/wall/hole.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/hole.png")) - .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { + .addComponent>("assets/wall/hole.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/hole.png")); + /* .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) { std::cout << "Bumper Created" << std::endl; scene->addEntity("Bumper Block") - .addComponent(Vector3f(coords.x, coords.y - 1, coords.z)) - .addComponent>("assets/wall/bumper.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/bumper.png")) - .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { + .addComponent(Vector3f(coords.x, coords.y, coords.z)) + .addComponent>("assets/wall/bumper.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/bumper.png")); + /* .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { if (other.hasComponent()) { auto &movable = other.getComponent(); movable.addForce(Vector3f(0, 5, 0)); } - }); + }); */ } void MapGenerator::createStairs(Vector3f coords, std::shared_ptr scene) @@ -138,7 +148,7 @@ namespace BBM std::cout << "Stairs Created" << std::endl; scene->addEntity("Stairs Block") .addComponent(coords) - .addComponent(1) + //.addComponent(1) .addComponent>("assets/wall/stairs.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/stairs.png")); } @@ -163,23 +173,25 @@ namespace BBM MapGenerator::MapBlock MapGenerator::createHeight(MapBlock map, int width, int height) { - double rnd = static_cast(std::rand())/RAND_MAX; + //double rnd = static_cast(std::rand())/RAND_MAX; + + double rnd = 1; std::cout << "Height rnd" << rnd << std::endl; if (rnd > 0.60) { std::cout << "Up border" << std::endl; 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)] = FLOOR; + map[std::make_tuple(i, 0, height)] = UPPERFLOOR; map[std::make_tuple(i, 1, 0)] = map[std::make_tuple(i, 0, 0)]; - map[std::make_tuple(i, 0, 0)] = FLOOR; + map[std::make_tuple(i, 0, 0)] = UPPERFLOOR; } map[std::make_tuple(0, 0, height - 1)] = STAIRS; map[std::make_tuple(0, 0, 1)] = STAIRS; map[std::make_tuple(width, 0, height - 1)] = STAIRS; map[std::make_tuple(width, 0, 1)] = STAIRS; - map[std::make_tuple(width / 2, -1, height - 1)] = BUMPER; - map[std::make_tuple(width / 2, -1, 1)] = BUMPER; + map[std::make_tuple(width / 2, 0, height - 1)] = BUMPER; + map[std::make_tuple(width / 2, 0, 1)] = BUMPER; } if (rnd > 0.30) { std::cout << "Up center" << std::endl; @@ -188,7 +200,7 @@ namespace BBM 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)] = FLOOR; + map[std::make_tuple(i, 0, j)] = UPPERFLOOR; } } map[std::make_tuple(width / 2 - width / 8, 0, height / 2 + height / 4 + 1)] = STAIRS; @@ -209,6 +221,18 @@ namespace BBM return map; } + MapGenerator::MapBlock MapGenerator::cleanBreakable(MapBlock map, int width, int height) + { + for (int i = 0; i < width + 1; i++) + for (int j = 0; j < height; j++) { + if (map[std::make_tuple(i, 0, j)] == BREAKABLE && isCloseToBlockType(map, i, 0, j, STAIRS)) + map[std::make_tuple(i, 0, j)] = NOTHING; + 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; + } + return (map); + } + MapGenerator::MapBlock MapGenerator::createMap(int width, int height) { MapBlock map; @@ -237,6 +261,7 @@ namespace BBM if (!((i + 1) % 2) && !((j + 1) % 2)) map[std::make_tuple(i, 0, j)] = UNBREAKABLE; map = createHeight(map, width, height); + map = cleanBreakable(map, width, height); return (map); } diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 0679c524..865e6563 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -34,6 +34,7 @@ namespace BBM NOTHING, BREAKABLE, HOLE, + UPPERFLOOR, FLOOR, BUMPER, STAIRS, @@ -98,9 +99,14 @@ namespace BBM //! @param coords coords of the element //! @param scene Scene where the map is instanced - //! @brief Create bumper of the map + //! @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 @@ -119,6 +125,13 @@ namespace BBM //! @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 Clean breakable on stairs, bumpers, etc.. + static MapBlock cleanBreakable(MapBlock map, int width, int height); + + public: diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 36b96603..db3896c9 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -88,7 +88,7 @@ namespace BBM }, 3); scene->addEntity("camera") - .addComponent(8, 15, -15) + .addComponent(8, 20, 7) .addComponent(Vector3f(8, 0, 8)); std::srand(std::time(NULL)); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);