Procedural terrain generation

I leave you a procedural generation project done in a few hours, I am not going to continue modifying it but if someone comes up with how to optimize it a little more I would like you to tell me :smiley:

terrain2d-1

2 Likes

Did you use any type of tile map

1 Like

no, just use sprites, and the whole project is programmed in typescript.

1 Like

just wondering, how does this work(especially cave systems) and can this project use seeds?

I am not going to explain how the perlin noise function works as it is complex, but I recommend looking for information on the subject.
Summarizing my implementation of the function it returns a number between 0 and 1, for the surface I use perlin noise 1d and for the caves perlin noise 2d.
In the terrain.ts file there is a variable called CAVES_FREQ, which is used to know if an air block should be generated based on the value returned by the perlin noise 2d. If the value is greater than CAVES_FREQ, stone is generated, otherwise air is generated.

And yes, the project internally uses seeds, it is also a variable from terrain.ts, although I did not set an option for the user to modify it, so the seed is random and its range is from -10000 to 10000.

// terrain.ts line 10
static readonly SEED = randint(-10000, 10000)

Although the seed is not used to generate the transition between stone and dirt, so every time you generate the same chunk, the transition between these blocks will be generated again at random.

1 Like

I just changed how the BlockPool class works, now around 1000 blocks are created on average, before it was around 1500, so the performance has increased and the initial load has been reduced. :smiley:

2 Likes

I just realized, It seems like the chunks generate procedurally on the y axis, so you can go down forever! that’s cool! Minecraft doesn’t even do that

I rebuilt the project with some changes and performance may have improved, does it show?
Now the blocks are Tiles, but I keep generation infinite :wink:

2 Likes