How do I Spawn semi-random number of objects on grid

Get help using Construct 2

Post » Sun May 15, 2016 7:26 pm

I'm trying to make a Breakout clone with randomized levels. I want the bricks, which are set up in a family, to spawn at the start of a layout. I'm trying to get between 35-150 bricks to spawn in a specific part of a grid when the layout starts. Is there a way to do this in this way or do I need to create a spawner sprite?
B
3
Posts: 1
Reputation: 177

Post » Sun May 15, 2016 8:45 pm

Do a for loop("x") for 1 to number of bricks in a row, within another for loop("y") for 1 to number of rows. I suggest setting the origin of the brick sprites to the lower-left corner, unless you want to offset the math I wrote below.

Under the bottom level loop("x") add a condition "compare two values" Random(0,100)>20 (that's 80% odds, adjust as you see fit), and do the following actions:

System actions>create object at layer 0 (or whichever you wish) x = (brick.width*loopindex("x"))+left boundary, y=(brick.height*loopindex("y"))+upper boundary.


EDIT:

Changing the left boundary and upper boundary as well as the number of rows and number of bricks per row will make the bricks appear only in a specific part of an area/grid. Upper boundary and left boundary can be variables (randomly set at that), ditto for number of rows or number of bricks per row.

Ok, maybe leave the origin as top-left and start from for 0 to (desired row total number-1), bottom-left origin is counter-intuitive:

Image
B
15
S
6
Posts: 85
Reputation: 1,195


Return to How do I....?

Who is online

Users browsing this forum: Christmas and 55 guests