Answer the question
In order to leave comments, you need to log in
How to properly generate a level?
I have a simple location (side view, i.e. platformer), the character runs and spikes stick out of the ground to meet him, how can I randomly scatter them on the main (running) platform?
Using libgdx and using Math,utils,random(), I randomly scattered them around the map, but they either stick together or are too close to each other, what should I do?
Answer the question
In order to leave comments, you need to log in
https://en.wikipedia.org/wiki/Perlin Noise , one-dimensional case
Or choose the desired distribution.
You generate sequentially. Randomly choose the distance to the next spike. You set the minimum and maximum distance: distance = random(min, max). That way they won't stick together and won't be too sparse.
You create an array of points where you will have spikes, then sort it and when creating it, you simply check that they are no closer than the width of the spike + some minimum required distance between the spikes. If everything is OK, then you draw the spike, if not, you take the next element, but compare it with the last one drawn.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question