fix coding style

This commit is contained in:
Askou
2021-06-01 17:30:58 +02:00
parent 402b5386c5
commit 07f466ca67
2 changed files with 35 additions and 28 deletions
+34 -27
View File
@@ -11,8 +11,8 @@ namespace BBM
{
void MapGenerator::generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene)
{
std::string UnbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string UnbreakablePnj = "assets/wall/unbreakable_wall.png";
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png";
for (int i = 0; i < width + 1; i++) {
for (int j = 0; j < height + 1; j++) {
@@ -20,7 +20,7 @@ namespace BBM
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(Vector3f(i, 0, j))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj));
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj));
}
}
}
@@ -28,25 +28,25 @@ namespace BBM
void MapGenerator::generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene)
{
std::string UnbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string UnbreakablePnj = "assets/wall/unbreakable_wall.png";
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png";
scene->addEntity("Bottom Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj), RAY::Vector3(width + 3, 1, 1));
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Upper Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj), RAY::Vector3(width + 3, 1, 1));
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Left Wall")
.addComponent<PositionComponent>(Vector3f(width + 1, 0, (height + 1) / 2))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj), RAY::Vector3(1, 1, height + 3));
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
scene->addEntity("Right Wall")
.addComponent<PositionComponent>(Vector3f(-1, 0, (height + 1) / 2))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>(UnbreakableObj, std::make_pair(MAP_DIFFUSE, UnbreakablePnj), RAY::Vector3(1, 1, height + 3));
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
}
void MapGenerator::generateFloor(int width, int height, std::shared_ptr<WAL::Scene> scene)
@@ -145,35 +145,37 @@ namespace BBM
MapGenerator::BlockType MapGenerator::getRandomBlockType()
{
double rnd = static_cast<double>(std::rand())/RAND_MAX;
double rnd = static_cast<double>(std::rand())/RAND_MAX;
if (rnd > 0.95)
return HOLE;
if (rnd > 0.10)
return BREAKABLE;
return NOTHING;
return NOTHING;
}
MapGenerator::MapBlock MapGenerator::createHeight(MapBlock map, int width, int height)
{
double rnd = static_cast<double>(std::rand())/RAND_MAX;
if (rnd > 0.60)
if (rnd > 0.60) {
for (int i = 0; i < width; i++) {
map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)];
map[std::make_tuple(i, 0, height)] = NOTHING;
map[std::make_tuple(i, 0, height)] = FLOOR;
}
for (int j = 0; j < height; j++) {
map[std::make_tuple(width, 1, j)] = map[std::make_tuple(width, 0, j)];
map[std::make_tuple(width, 0, j)] = NOTHING;
map[std::make_tuple(width, 0, j)] = FLOOR;
}
if (rnd > 0.30)
}
if (rnd > 0.30) {
for (int i = width - width/4; i < width + width/4 + 1; i++) {
for (int j = height - height/4; j < height + height/4 + 1; j++) {
map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)];
map[std::make_tuple(i, 0, j)] = NOTHING;
map[std::make_tuple(i, 0, j)] = FLOOR;
}
}
}
return map;
}
@@ -193,39 +195,44 @@ namespace BBM
width = width % 2 ? width + 1 : width;
height = height % 2 ? height + 1 : height;
for (int i = 0; i < width; i++)
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++)
map[std::make_tuple(i, 0, j)] = NOTHING;
}
map = createSpawner(map, width, height);
for (int i = 0; i < width + 1; i++) {
for (int j = 0; j < height + 1; j++) {
if (map[std::make_tuple(i, 0, j)] == SPAWNER)
continue;
if (isCloseToBlockType(map, i , 0, j, SPAWNER)) {
if (isCloseToBlockType(map, i , 0, j, SPAWNER))
map[std::make_tuple(i, 0, j)] = NOTHING;
} else {
else
map[std::make_tuple(i, 0, j)] = getRandomBlockType();
}
if (map[std::make_tuple(i, 0, j)] == UNBREAKABLE && isCloseToBlockType(map, i, 0, j, UNBREAKABLE))
map[std::make_tuple(i, 0, j)] = BREAKABLE;
}
}
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;
}
}
map = createHeight(map, width, height);
return (map);
}
void MapGenerator::loadMap(int width, int height, std::map<std::tuple<int, int, int>, \
BlockType> map, std::shared_ptr<WAL::Scene> scene)
{
void MapGenerator::loadMap(int width, int height, std::map<std::tuple<int, int, int>,
BlockType> map, std::shared_ptr<WAL::Scene> scene)
{
generateWall(width, height, scene);
generateFloor(width, height, scene);
for (int x = 0; x < width + 1; x++)
for (int z = 0; z < height + 1; z++)
for (int x = 0; x < width + 1; x++) {
for (int z = 0; z < height + 1; z++) {
for (int y = 0; y < 1 + 1; y++)
createElement(Vector3f(x, y, z), scene, map[std::make_tuple(x, y, z)]);
}
}
}
} // namespace BBM
+1 -1
View File
@@ -28,7 +28,6 @@ namespace BBM
class MapGenerator
{
private:
using MapElem = std::function<void (Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
//! @brief Enum of the block available.
enum BlockType {
NOTHING,
@@ -41,6 +40,7 @@ namespace BBM
UNBREAKABLE
};
using MapElem = std::function<void (Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
//! @brief Generate random block type