How do I generate a level randomly?
Posted
by
Charlton Santana
on Game Development
See other posts from Game Development
or by Charlton Santana
Published on 2012-04-09T21:05:11Z
Indexed on
2012/04/09
23:49 UTC
Read the original article
Hit count: 316
I am currently hard coding 10 different instances like the code below, but but I'd like to create many more. Instead of having the same layout for the new level, I was wondering if there is anyway to generate a random X value for each block (this will be how far into the level it is). A level 100,000 pixels wide would be good enough but if anyone knows a system to make the level go on and on, I'd like to know that too. This is basically how I define a block now (with irrelevant code removed):
block = new Block(R.drawable.block, 400, platformheight);
block2 = new Block(R.drawable.block, 600, platformheight);
block3 = new Block(R.drawable.block, 750, platformheight);
The 400
is the X position, which I'd like to place randomly through the level, the platformheight
variable defines the Y position which I don't want to change.
© Game Development or respective owner