W
W
wolf-98302015-02-06 20:04:15
Java
wolf-9830, 2015-02-06 20:04:15

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

3 answer(s)
D
Don Kaban, 2015-02-06
@donkaban

https://en.wikipedia.org/wiki/Perlin Noise , one-dimensional case
Or choose the desired distribution.

S
Sergey Lerg, 2015-02-07
@Lerg

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.

K
Kirill Penzin, 2015-02-06
@kir_vesp

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 question

Ask a Question

731 491 924 answers to any question