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?
Develop games in your browser. Powerful, performant & highly capable.
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.
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: