I would like to create an RNG generation for my resources in an island survival game i’m trying to create
I would like to know how i would give random position to creating an object, a random number of times, but only on a certain ground “type”. the ground i am using has water, sand, dirt, and grass, but as tileable sprites. i have tested using regular sprites and stacking them in a grid, but that made the gdevelop preview incredibly laggy, and messed up the particular events and such that i was using.
So far, i have gotten RNG positioning done, but i don’t know/can’t figure out how to give it an RNG value, or how to have the trees only spawn on “grass”
Shown here is what i currently use, to randomly put trees within the grass for testing, but i don’t want to have the island end as a rectangle (i want to allow for RNG land generation later) and i can’t figure out how i would give a chance to spawn a tree on each grass area for something like a curve or something, while not spawning on dirt or water, etc.
notes: im using a 32x32 grid for my game (hence the RandomInRange()*32, which is the x and y start and end values for my grass rectangle)
As for creating something on specific surface type
You could go with condition
Water in collision with Grass < inverse this conditon
Create Grass RandomInRange
If inversing does not work you can try NOT condition
Also idk if you should go with water in collision with grass or grass in collision with water
Other thing to do is just create grass as you do
Then just condition
Water in collision with grass
Then you could count how many grass you have and if it is not as much as you want you repeat creating process
Look on what im working
I got it working but updating tiles system is very NOT FRIENDLY for performace
Few days ago i came up with some ideas how to optimize it but it will take a lot of time to test them
for the grass and water part, im assuming you mean for the island generation shape, right? But then, wouldn’t the collision remove all grass? or no? because if the grass is based off of the collision of water, how would i get a random shape? unless you mean something similar to “biomes” within the island itself?
If i understood your question correctly then you wanted to NOT spawn something on some type of other thing
For example you did not want to spawn grass or tree on water
Or maybe not a flower or rock on stone tile
And in collision condition you have this
Set it to yes and if you have idk dirt and next to it you have water tile
Then grass tile will be able to spawn on that dirt tile
Since it is not checking if objects are touching by their sides but if one is actually inside space of another one
And that would work for every other tile
Only downside is that you will need to make A LOT conditions to make everything work as you want
EDIT: I just realized that you said you were using tiled sprites. I’m so sorry. My idea is for regular sprites. Tiled sprites don’t have points. Maybe this concept can be modified.
Hi. Can you post a picture of your project with all of the terrain so we can get a better idea of the size and shape of the areas that you’re using and the size of the resources?
My initial thought is to add points to the objects so you can pick a random object and then choose a random point on the object. You could use an array to track the points. Each element would be a point. Pick a random element and use the value of the element not the element itself. Remove the elements as items are added and add them back as you remove items.
This was interesting. It might not work for you but it’s still an interesting concept. A lot of my code is just for testing. I added a list of the points remaining for each object and I placed a text object at each point location. Again, just for testing.
Click the random button to add trees. Click the tree to delete it.
That looks really nice!
How did you make it? Is there any tutorial? would love to learn that
The source files are linked. It uses a random number concept that I use fairly often. You add a number to an array and pick a random element and then use the element value not the random number. The array corresponds with the predefined points. The points are named “Point0” through “Point11” so you pick a point based on “Point” + the number in the array. You remove the point from the array as you add trees and when you delete a tree you put the number stored in the tree object back as an id back into the array.
Most of the code is for testing. Later today, I could make a slimmed down version with just the necessary parts and add some comments.
I see I see
But what if i want use that same method in game like for example (if the player can build fences then it needs to be connectable seamlessly)
so is that going to work?
Here’s the barebones version. No comments but there’s really not a lot of code. I added points to the islands and a numberOfPoints variable because I don’t know if there’s an easy way to get the number of points an object has. I gave the islands id numbers but I think that was only needed for the text object. Some spots I has to subtract 1 because arrays start at zero.
Thank you i will try it out😀
I honestly don’t know. If you had points in a line then I guess you could use them for the fence. The points could be named differently. I didn’t know what your scene had. My thinking was if you pick a random island then you add island related items. Sand related. This might only work for parts of it or maybe not at all. It’s just an idea.
These are the points I added to the island.
The concept reminded me of Heroes of Might and Magic. I loved that game.
Ah i see well i will try the points method.
Heroes of Might and Magic never heard of that but the graphics reminded me of TTD (Transport Tycoon)
It’s good game
The early versions were good but then they made the graphics smaller and changed the perspective. It just wasn’t the same. It was also very time-consuming. It had upper and lower world, a lot of different types of monsters and heroes. It was fun.
Hmm seems like a fun game
It is extension i am working on
1 - Preparing Spritesheet to then slice it into individual sprites is a bit of work since it looks like this
And you need to make all tiles like in the picture above which in the end looks like this
Since issue is that tiles with inner corners SHOULD be separate object
But since gdevelop starts to drop FPS very fast if you have too many tiles on SCENE (not even on screen)
I decided not to go with separate objects for inner corners
Since in some cases you would have 4 objects on one tile cell
2 - The way updating tiles work is VERY VERY VERY and i really mean VERY not optimized
Since either i can update all tiles on scene = FPS LAG
Update only tiles that are on your actual view port
BUT that means updating needs to happen every few steps your player make
And if you zoom out too much you really feel LAG SPIKE
So you need to have your game zoomed in
3 - On top of that if i go with 1st method where i update all tiles on SCENE i can have like 2-3 tiles on scene before it will start to FPS drop while just moving
With updating only tiles that are inside your view port i can get around 8k of tiles on SCENE before FPS drop starts to happen
And you really feel like walking underwater
GDcraft includes project you saw on gif + AutoTile extension
So you don’t need to download extension alone
There is only one action to set object to Tile so i doubt you need explanation
You can check my events to see how i did set up grind and stuff
All you need to know is there
IF i find a way to update only tiles that are adjacent to tile that was created or destroyed WITH limiting how far updating goes (should go 2 tiles ahead so from created/deleted tile 2 tile spaces in all directions)
We will have 8k of tiles on scene and NO FPS drop while creating/destroying tiles
And on updating per few player steps
Problem is all methods i found acts like this
IF i update 2 tiles from center tile
Then each 3rd tile will act as it does not exist and won’t connect with updated tiles neither updated tiles will connect with 3rd space tiles
Basically you get this
Yeah i have noticed the lag thing too
And that sounds so complicated
And about the tiles so how is that going to work? Like to use the extension the user has to make all the tiles in one tile object?
Or is there any other way ?
You can prepare each tile image manually looking at my screenshots
But i would suggest making that spritesheet then slicing it with this for example
After you slice them you add them as 1 single animation to one object in same order they are
So basically you just go double click your sprite object
Click add sprite
And select all sprites that were sliced by sprit sheet slicer from sprite sheet
And you are done
I just tried your json it is looking good so far i really liked the hit sound.
I noticed the sprite it’s just as you said
Guess where i get it from
How did you make it? Is there any tutorial? would love to learn that