Position spawned platforms randomly

Hi Coronaville  :lol:

I am trying to make a game similar to Doodle Jump.

I am having problem to randomly position spawned platforms on the screen (in Portrait).

Tried everything:

Nothing works, in most of the cases generated platforms are stacked together, or very close to each other.

Can somebody please please help with intelligent suggestion?  :smiley:

Many, many, many thanks!

G

Hey gogigoranic8,

a grid is not the optimal solution for this, because you wont fill out most of the grid and it also reduces your flexibility.

What you are looking for is a simple procedural level generation. One of the major problems with that is the randomness (as you alreday experienced). So what you need is some kind of “controled” randomness, so that thngs are random but no too much. Most times you are doing this is by keeping track of allready placed stuff and check if it fullfills the conditions your game needs. For that you define some variables that determine the minimum and maximum values/distances of your level.

I will give a short example that might work as a startingpoint for your games level creation.

local levelWidth = 600 --the width of your game local levelHeight = 10000 --the height of the area you want to create plattforms for local minDistanceY = 100 --the minimum y distance between to plattforms local maxDistanceY = 400 --the maximum y distance between to plattforms local plattformWidth = 100 --the plattform width local plattforms = {} --a table that holds all created plattforms local currentHeight = 0 --y position of the last position plattform local currentIndex = 0 --number of plattforms created while currentHeight \< levelHeight do --if the current height is smaller than the height of the level then create another plattform currentIndex = currentIndex + 1 --increment the index local newPlattform = { x = math.random(plattformWidth\*0.5, levelWidth - plattformWidth\*0.5) --plattform x position, taing into account its width y = currentHeight, } plattforms[currentIndex] = newPlattform currentHeight = currentHeight + math.random(minDistanceY, maxDistanceY) --estimate y position of next plattform end

Of course you can add more randomness and more if checks. this is the most basic example.

Hope that helps, greetings

Torben :slight_smile:

Hi Torbenratzlaff,

I will try this out, and let you know who it turned out!

Many many thanks!  :D 

G

Hi Torbenratzlaff,

Looks good.

Little modifications will be necessary, but this is just what I was looking for!

Thanks!  :D 

G

Great to hear :slight_smile:

Hey gogigoranic8,

a grid is not the optimal solution for this, because you wont fill out most of the grid and it also reduces your flexibility.

What you are looking for is a simple procedural level generation. One of the major problems with that is the randomness (as you alreday experienced). So what you need is some kind of “controled” randomness, so that thngs are random but no too much. Most times you are doing this is by keeping track of allready placed stuff and check if it fullfills the conditions your game needs. For that you define some variables that determine the minimum and maximum values/distances of your level.

I will give a short example that might work as a startingpoint for your games level creation.

local levelWidth = 600 --the width of your game local levelHeight = 10000 --the height of the area you want to create plattforms for local minDistanceY = 100 --the minimum y distance between to plattforms local maxDistanceY = 400 --the maximum y distance between to plattforms local plattformWidth = 100 --the plattform width local plattforms = {} --a table that holds all created plattforms local currentHeight = 0 --y position of the last position plattform local currentIndex = 0 --number of plattforms created while currentHeight \< levelHeight do --if the current height is smaller than the height of the level then create another plattform currentIndex = currentIndex + 1 --increment the index local newPlattform = { x = math.random(plattformWidth\*0.5, levelWidth - plattformWidth\*0.5) --plattform x position, taing into account its width y = currentHeight, } plattforms[currentIndex] = newPlattform currentHeight = currentHeight + math.random(minDistanceY, maxDistanceY) --estimate y position of next plattform end

Of course you can add more randomness and more if checks. this is the most basic example.

Hope that helps, greetings

Torben :slight_smile:

Hi Torbenratzlaff,

I will try this out, and let you know who it turned out!

Many many thanks!  :D 

G

Hi Torbenratzlaff,

Looks good.

Little modifications will be necessary, but this is just what I was looking for!

Thanks!  :D 

G

Great to hear :slight_smile: