Correction des arbres.
This commit is contained in:
parent
d444b4de30
commit
2c73a2ed00
@ -113,14 +113,13 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
|
|
||||||
|
|
||||||
#pragma region Arbre
|
#pragma region Arbre
|
||||||
|
|
||||||
double valeurRnd = 0;
|
double valeurRnd = 0;
|
||||||
int treeheight = 10;
|
int treeheight = 10;
|
||||||
|
|
||||||
int lastTreeX = -1;
|
int lastTreeX = -1;
|
||||||
int lastTreeZ = -1;
|
int lastTreeZ = -1;
|
||||||
|
|
||||||
int minDistanceBetweenTrees = 10;
|
int minDistanceBetweenTrees = 10; // Définir la distance minimale entre les arbres
|
||||||
|
|
||||||
|
|
||||||
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) {
|
for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) {
|
||||||
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) {
|
||||||
@ -137,13 +136,10 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
|
height = height * 2000. * simplex.eval((double)(ix + x * CHUNK_SIZE_X) / 512., (double)(iz + y * CHUNK_SIZE_Z) / 512.);
|
||||||
height /= (CHUNK_SIZE_Y / 1.9);
|
height /= (CHUNK_SIZE_Y / 1.9);
|
||||||
height += 15.;
|
height += 15.;
|
||||||
|
if (GetBlock(ix, (int)height, iz) == BTYPE_GRASS || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) {
|
||||||
if (GetBlock(ix, (int)height, iz) == BTYPE_DIRT || (GetBlock(ix, (int)height, iz) == BTYPE_METAL)) {
|
|
||||||
valeurRnd = simplex.eval(xnoiz, ynoiz);
|
valeurRnd = simplex.eval(xnoiz, ynoiz);
|
||||||
|
|
||||||
int distanceThreshold = 20;
|
int distanceThreshold = 20;
|
||||||
|
// Vérifie si l'emplacement n'est pas à l'intérieur des lacs
|
||||||
// V<>rifie si l'emplacement n'est pas <20> l'int<6E>rieur des lacs
|
|
||||||
bool isInsideLake = false;
|
bool isInsideLake = false;
|
||||||
for (int iy = 0; iy < 13; ++iy) {
|
for (int iy = 0; iy < 13; ++iy) {
|
||||||
if (GetBlock(ix, iy, iz) == BTYPE_ICE) {
|
if (GetBlock(ix, iy, iz) == BTYPE_ICE) {
|
||||||
@ -151,7 +147,6 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31)
|
if (!isInsideLake && ((valeurRnd > -0.4 && valeurRnd < -0.38) || (valeurRnd > -0.35 && valeurRnd < -0.31)
|
||||||
|| (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39))
|
|| (valeurRnd > 0.3 && valeurRnd < 0.32) || (valeurRnd > 0.37 && valeurRnd < 0.39))
|
||||||
) {
|
) {
|
||||||
@ -163,9 +158,7 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
if (treeheight < 5)
|
if (treeheight < 5)
|
||||||
treeheight = 5;
|
treeheight = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlaceTree(ix, height, iz, treeheight);
|
PlaceTree(ix, height, iz, treeheight);
|
||||||
|
|
||||||
lastTreeX = ix;
|
lastTreeX = ix;
|
||||||
lastTreeZ = iz;
|
lastTreeZ = iz;
|
||||||
}
|
}
|
||||||
@ -174,7 +167,6 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
@ -183,6 +175,7 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//else {
|
//else {
|
||||||
// input.seekg(0, std::ios_base::end);
|
// input.seekg(0, std::ios_base::end);
|
||||||
// int size = input.tellg();
|
// int size = input.tellg();
|
||||||
@ -220,18 +213,32 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Chunk::PlaceTree(int x, int y, int z, int height) {
|
void Chunk::PlaceTree(int x, int y, int z, int height) {
|
||||||
|
// Vérifie si les coordonnées x, y, z sont dans les limites du chunk
|
||||||
for (int iy = 0; iy < height + 1; ++iy) {
|
if (x < 0 || x >= CHUNK_SIZE_X || y < 0 || y >= CHUNK_SIZE_Y || z < 0 || z >= CHUNK_SIZE_Z) {
|
||||||
SetBlock(x, y + iy, z, BTYPE_DIRT, nullptr);
|
// Coordonnées hors limites du chunk, sortie anticipée pour éviter tout accès non valide
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int foliageHeight = height / 2;
|
// Place la tige de l'arbre
|
||||||
|
for (int iy = 0; iy < height + 1; ++iy) {
|
||||||
|
if (y + iy < CHUNK_SIZE_Y) { // Vérifie si la hauteur est à l'intérieur des limites du chunk
|
||||||
|
SetBlock(x, y + iy, z, BTYPE_DIRT, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int dy = 1; dy < foliageHeight; ++dy) {
|
// Place les feuilles de l'arbre
|
||||||
for (int dx = -3; dx <= 3; ++dx) {
|
int foliageHeight = height / 2;
|
||||||
for (int dz = -3; dz <= 3; ++dz) {
|
for (int dy = 0; dy < foliageHeight; ++dy) {
|
||||||
if (dx * dx + dy * dy + dz * dz < 10) {
|
for (int dx = -4; dx <= 4; ++dx) {
|
||||||
SetBlock(x + dx, y + height + dy, z + dz, BTYPE_GREENGRASS, nullptr);
|
for (int dz = -4; dz <= 4; ++dz) {
|
||||||
|
// Vérifie que les coordonnées se trouvent à l'intérieur des limites du chunk
|
||||||
|
if (x + dx >= 0 && x + dx < CHUNK_SIZE_X && y + height + dy >= 0 && y + height + dy < CHUNK_SIZE_Y &&
|
||||||
|
z + dz >= 0 && z + dz < CHUNK_SIZE_Z) {
|
||||||
|
// Vérifie si le bloc est à une distance acceptable du centre des feuilles pour les placer
|
||||||
|
double distanceSquared = dx * dx + dy * dy + dz * dz;
|
||||||
|
if (distanceSquared < 20) {
|
||||||
|
SetBlock(x + dx, y + height + dy, z + dz, BTYPE_GREENGRASS, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,28 +318,8 @@ void Chunk::MakeModified() { m_isModified = true; }
|
|||||||
|
|
||||||
void Chunk::Structure(int x, int y, int z,int height)
|
void Chunk::Structure(int x, int y, int z,int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < height; i++)
|
for (int i = 0; i < height; i++)
|
||||||
{
|
{
|
||||||
SetBlock(x, i + y, z, BTYPE_GRASS, nullptr);
|
SetBlock(x, i + y, z, BTYPE_GRASS, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user