add basic depths with stairs and bumper to access it

This commit is contained in:
TrueBabyChaise
2021-06-02 15:03:13 +02:00
parent d2ba552f61
commit 0d7d26b0f9
10 changed files with 211 additions and 50 deletions
+12
View File
@@ -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
+61
View File
@@ -0,0 +1,61 @@
# hole.obj
#
mtllib hole.mtl
o hole
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
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 22 KiB

+12
View File
@@ -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
+61
View File
@@ -0,0 +1,61 @@
# hole.obj
#
mtllib hole.mtl
o hole
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
Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

+63 -48
View File
@@ -11,8 +11,8 @@ namespace BBM
{ {
void MapGenerator::generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene) void MapGenerator::generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene)
{ {
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj"; std::string UnbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png"; std::string UnbreakablePnj = "assets/wall/unbreakable_wall.png";
for (int i = 0; i < width + 1; i++) { for (int i = 0; i < width + 1; i++) {
for (int j = 0; j < height + 1; j++) { for (int j = 0; j < height + 1; j++) {
@@ -20,7 +20,7 @@ namespace BBM
scene->addEntity("Unbreakable Wall") scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(Vector3f(i, 0, j)) .addComponent<PositionComponent>(Vector3f(i, 0, j))
//.addComponent<CollisionComponent>(1) //.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,33 +28,38 @@ namespace BBM
void MapGenerator::generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene) void MapGenerator::generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene)
{ {
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj"; std::string UnbreakableObj = "assets/wall/unbreakable_wall.obj";
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png"; std::string UnbreakablePnj = "assets/wall/unbreakable_wall.png";
scene->addEntity("Bottom Wall") scene->addEntity("Bottom Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1)) .addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
//.addComponent<CollisionComponent>(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") scene->addEntity("Upper Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1)) .addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
//.addComponent<CollisionComponent>(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") scene->addEntity("Left Wall")
.addComponent<PositionComponent>(Vector3f(width + 1, 0, (height + 1) / 2)) .addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
//.addComponent<CollisionComponent>(1) //.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 + 1));
scene->addEntity("Right Wall") scene->addEntity("Right Wall")
.addComponent<PositionComponent>(Vector3f(-1, 0, (height + 1) / 2)) .addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
//.addComponent<CollisionComponent>(1) //.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 + 1));
} }
void MapGenerator::generateFloor(int width, int height, std::shared_ptr<WAL::Scene> scene) void MapGenerator::generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene)
{ {
scene->addEntity("Floor") for (int i = 0; i < width + 1; i++) {
.addComponent<PositionComponent>(Vector3f(width / 2, -1, height / 2)) for (int j = 0; j < height + 1; j++) {
//.addComponent<CollisionComponent>(1) if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, 0, j)] != BUMPER)
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"), RAY::Vector3(width + 2, 0, height + 2)); scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(Vector3f(i, -1, j))
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"));
}
}
} }
void MapGenerator::createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType) void MapGenerator::createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType)
@@ -64,8 +69,8 @@ namespace BBM
{UNBREAKABLE, &createUnbreakable}, {UNBREAKABLE, &createUnbreakable},
{HOLE, &createHole}, {HOLE, &createHole},
{FLOOR, &createFloor}, {FLOOR, &createFloor},
/* {BUMPER, &createBumper}, {BUMPER, &createBumper},
{STAIRS, &createStairs} */ {STAIRS, &createStairs}
}; };
try { try {
@@ -115,10 +120,11 @@ namespace BBM
} }
void MapGenerator::createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene) void MapGenerator::createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
{ {
std::cout << "Bumper Created" << std::endl;
scene->addEntity("Bumper Block") scene->addEntity("Bumper Block")
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z)) .addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z))
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/bumper_block.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/bumper_block.png")); .addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/bumper.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/bumper.png"));
/* .addComponent<CollisionComponent>([](const WAL::Entity &entity, WAL::Entity &other) { /* .addComponent<CollisionComponent>([](const WAL::Entity &entity, WAL::Entity &other) {
if (other.hasComponent<MovableComponent>()) { if (other.hasComponent<MovableComponent>()) {
auto &movable = other.getComponent<MovableComponent>(); auto &movable = other.getComponent<MovableComponent>();
@@ -129,10 +135,11 @@ namespace BBM
void MapGenerator::createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene) void MapGenerator::createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
{ {
std::cout << "Stairs Created" << std::endl;
scene->addEntity("Stairs Block") scene->addEntity("Stairs Block")
.addComponent<PositionComponent>(coords) .addComponent<PositionComponent>(coords)
//.addComponent<CollisionComponent>(1) //.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/stairs_block.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/stairs_block.png")); .addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/stairs.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/stairs.png"));
} }
bool MapGenerator::isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType) bool MapGenerator::isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType)
@@ -145,36 +152,49 @@ namespace BBM
MapGenerator::BlockType MapGenerator::getRandomBlockType() 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) if (rnd > 0.95)
return HOLE; return HOLE;
if (rnd > 0.10) if (rnd > 0.25)
return BREAKABLE; return BREAKABLE;
return NOTHING; return NOTHING;
} }
MapGenerator::MapBlock MapGenerator::createHeight(MapBlock map, int width, int height) MapGenerator::MapBlock MapGenerator::createHeight(MapBlock map, int width, int height)
{ {
double rnd = static_cast<double>(std::rand())/RAND_MAX; double rnd = static_cast<double>(std::rand())/RAND_MAX;
std::cout << "Height rnd" << rnd << std::endl;
if (rnd > 0.60) { if (rnd > 0.60) {
for (int i = 0; i < width; i++) { 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, 1, height)] = map[std::make_tuple(i, 0, height)];
map[std::make_tuple(i, 0, height)] = FLOOR; map[std::make_tuple(i, 0, height)] = FLOOR;
map[std::make_tuple(i, 1, 0)] = map[std::make_tuple(i, 0, 0)];
map[std::make_tuple(i, 0, 0)] = FLOOR;
} }
for (int j = 0; j < height; j++) { map[std::make_tuple(0, 0, height - 1)] = STAIRS;
map[std::make_tuple(width, 1, j)] = map[std::make_tuple(width, 0, j)]; map[std::make_tuple(0, 0, 1)] = STAIRS;
map[std::make_tuple(width, 0, j)] = FLOOR; 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;
} }
if (rnd > 0.30) { if (rnd > 0.30) {
for (int i = width - width/4; i < width + width/4 + 1; i++) { std::cout << "Up center" << std::endl;
for (int j = height - height/4; j < height + height/4 + 1; j++) { 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, 1, j)] = map[std::make_tuple(i, 0, j)];
map[std::make_tuple(i, 0, j)] = FLOOR; map[std::make_tuple(i, 0, j)] = FLOOR;
} }
} }
map[std::make_tuple(width / 2 - width / 8, 0, height / 2 + height / 4 + 1)] = STAIRS;
map[std::make_tuple(width / 2 + width / 8, 0, height / 2 - height / 4 - 1)] = STAIRS;
map[std::make_tuple(width / 2 - width / 4 - 1, 0, height / 2 - height / 8)] = STAIRS;
map[std::make_tuple(width / 2 + width / 4 + 1, 0, height / 2 + height / 8)] = STAIRS;
} }
return map; return map;
} }
@@ -195,44 +215,39 @@ namespace BBM
width = width % 2 ? width + 1 : width; width = width % 2 ? width + 1 : width;
height = height % 2 ? height + 1 : height; 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++) for (int j = 0; j < height; j++)
map[std::make_tuple(i, 0, j)] = NOTHING; map[std::make_tuple(i, 0, j)] = NOTHING;
}
map = createSpawner(map, width, height); map = createSpawner(map, width, height);
for (int i = 0; i < width + 1; i++) { for (int i = 0; i < width + 1; i++) {
for (int j = 0; j < height + 1; j++) { for (int j = 0; j < height + 1; j++) {
if (map[std::make_tuple(i, 0, j)] == SPAWNER) if (map[std::make_tuple(i, 0, j)] == SPAWNER)
continue; continue;
if (isCloseToBlockType(map, i , 0, j, SPAWNER)) if (isCloseToBlockType(map, i , 0, j, SPAWNER)) {
map[std::make_tuple(i, 0, j)] = NOTHING; map[std::make_tuple(i, 0, j)] = NOTHING;
else } else {
map[std::make_tuple(i, 0, j)] = getRandomBlockType(); map[std::make_tuple(i, 0, j)] = getRandomBlockType();
}
if (map[std::make_tuple(i, 0, j)] == UNBREAKABLE && isCloseToBlockType(map, i, 0, j, UNBREAKABLE)) if (map[std::make_tuple(i, 0, j)] == UNBREAKABLE && isCloseToBlockType(map, i, 0, j, UNBREAKABLE))
map[std::make_tuple(i, 0, j)] = BREAKABLE; map[std::make_tuple(i, 0, j)] = BREAKABLE;
} }
} }
for (int i = 0; i < width + 1; i++) { for (int i = 0; i < width + 1; i++)
for (int j = 0; j < height + 1; j++) { for (int j = 0; j < height + 1; j++)
if (!((i + 1) % 2) && !((j + 1) % 2)) if (!((i + 1) % 2) && !((j + 1) % 2))
map[std::make_tuple(i, 0, j)] = UNBREAKABLE; map[std::make_tuple(i, 0, j)] = UNBREAKABLE;
}
}
map = createHeight(map, width, height); map = createHeight(map, width, height);
return (map); return (map);
} }
void MapGenerator::loadMap(int width, int height, std::map<std::tuple<int, int, int>, void MapGenerator::loadMap(int width, int height, MapBlock map, std::shared_ptr<WAL::Scene> scene)
BlockType> map, std::shared_ptr<WAL::Scene> scene) {
{
generateWall(width, height, scene); generateWall(width, height, scene);
generateFloor(width, height, scene); generateFloor(map, width, height, scene);
for (int x = 0; x < width + 1; x++) { for (int x = 0; x < width + 1; x++)
for (int z = 0; z < height + 1; z++) { for (int z = 0; z < height + 1; z++)
for (int y = 0; y < 1 + 1; y++) for (int y = 0; y < 1 + 1; y++)
createElement(Vector3f(x, y, z), scene, map[std::make_tuple(x, y, z)]); createElement(Vector3f(x, y, z), scene, map[std::make_tuple(x, y, z)]);
}
}
} }
} // namespace BBM } // namespace BBM
+1 -1
View File
@@ -68,7 +68,7 @@ namespace BBM
//! @param height Height of the map //! @param height Height of the map
//! @param scene Scene where the map is instanced //! @param scene Scene where the map is instanced
//! @brief Generate the floor of the map //! @brief Generate the floor of the map
static void generateFloor(int width, int height, std::shared_ptr<WAL::Scene> scene); static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element //! @param coords coords of the element
//! @param scene Scene where the map is instanced //! @param scene Scene where the map is instanced
+1 -1
View File
@@ -75,7 +75,7 @@ namespace BBM
.addComponent<KeyboardComponent>() .addComponent<KeyboardComponent>()
.addComponent<MovableComponent>(); .addComponent<MovableComponent>();
scene->addEntity("camera") scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7) .addComponent<PositionComponent>(8, 15, -15)
.addComponent<CameraComponent>(Vector3f(8, 0, 8)); .addComponent<CameraComponent>(Vector3f(8, 0, 8));
std::srand(std::time(NULL)); std::srand(std::time(NULL));
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);