I would like to procedurally generate a map for my game and have the following events.
How do I…
Prevent the engine from placing rocks and trees in every tile and only generate them on tiles that meet the above conditions?
I would like to procedurally generate a map for my game and have the following events.
Prevent the engine from placing rocks and trees in every tile and only generate them on tiles that meet the above conditions?
You can use nested repeats. My objects are 32x32. Pay close attention to the indentation.
My result
Edit: This might also help. Instead of random, you can use the noise extension.
Can I ask why you are able to Declare variables? I dont seem to have that option available, I am new to Gdevelop.
These are the new local variables. You can use scene or global. Local variables only exist for that event and any sub-event of it. I like to use local variables for examples because I can capture everything with one screenshot. They’re good for one time use variables. They can keep the main variable lists a little shorter. They’re not useful for everything. Just one-time, disposable values.
https://wiki.gdevelop.io/gdevelop5/all-features/variables/local-variables/#local-variables
You can see in this example. The local variable color is valid for the 1st two events but it’s red on the last event because it’s not a sub-event. It’s a new event and the local variable gets removed once an event and its sub-events are executed.
Are you able to generate a project file for me to examine? I cannot wrap my head around the repeat function and I keep running into issues generating thousands and thousands of sprites when I intend to only generate a few.
My goal is to have 100 32x32 sprites lined up on the bottom of the screen as the “ground” and then references these individual sprites and place objects above them such as trees rocks etc. This would all look like a side scroller at the end.
This is a new concept to me as well. So, I can’t make any guarantees. There might be a better way.
I didn’t realize that you only need the 1 row. I thought you were making a top-down game.
This creates a row of ground. I kept it small for testng.
Try me: I added a randomize button to generate a new seed for the generator and sliders to demonstrate changing the ranges that are used. I used the lower range for the trees and the higher range for the rocks to decrease the chance of the ranges from overlapping.
https://gd.games/keith_13579/random-terrain
Source: (click the green [Code] button and then [download zip]
https://github.com/doug13579/Gdevelop-noise-generated-terrain
Events
scene variables
It uses the noise generator extension
Thank you so much for the detailed response. I will need to go over it a few times to get it to click but I am looking for a result almost identical to your example. Unfortunately this is all I have at the moment and It is only generating a rock and a tree at the first tile.
The last 2 events need to be subevents of the for each object. Move them one indentation to the right.
Hallelujah this is solved and looking great. Thank you so much Keith!