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

4 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:

3 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

1 Like

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:

3 Likes

i tried to make it so you couldn’t go through the blocks, and add physics, as if it were a game like terraria, but it didn’t work… could you try make something like that? pls

1 Like

I’ll do it why not, but I’m in midterms so it’ll be in my spare time. And I don’t remember much of what I did on that project either, so I probably changed a few things.

k thanks, jut an idea for when you’re bored maybe

Yo bro Welcome to the Forums

1 Like

thanks

I’ve added the collisions, biomes and a map (although the map was actually used for debugging).
I would need to add the caves and I want to do some optimizations.
I would like to see your project when you have it ready :+1:

2 Likes

Thank you!

hi, will this run smoothly on an XTRON pro, and is the terrain infinite?

Hi, I’m not sure what hardware is required to run it. As for whether the terrain is infinite, it is, or at least as infinite as a number can be within the framework haha.

2 Likes

on the most recent link, it is the same terrain every time…

I accidentally left the seed 9650 haha. You can enable randomness by uncommenting line 19 and commenting out line 20. Regards!

4 Likes

that fixed it, thanks!

1 Like