Variables:
X, Y, sX, sY = real variables, they represent X, respectively Y coordinates. sX and sY stands for startX/Y and are meant for the X and Y coordinates of the starting point.
col, row, index, i, j = integer variables, col = number of columns, row = number of rows, index = index for point array; variable i and j are just used for iteration in loops.
loc = point variable
spawnPoints = point array
First, manually calculate the number of columns and rows. If the smallest part is 32x32, then divide the total lenght/width of playable map area by 32.
For start point, take the upper-left-most corner of the playable map and offset it by half width and height of the smallest part. This way, you will always check center of each smallest part, not its upper-left most corner.
Code:
row = height / 32
col = width / 32
sX = coordinate X of upper-left-most corner + 16
sY = coordinate Y of upper-left-most corner + 16
for integer i from 0 to row do:
for integer j from 0 to col do:
X = sX + 32 * j
Y = sY + 32 * i
loc = location at X and Y
if (terrain at loc == brown terrain) do:
index = index + 1
spawnPoint[index] = loc
else
destroy loc
notice I do not destroy points that contain the brown terrain. Also, do not rewrite index, unless you destroy all points in spawnPoints array.
Lastly, I can spawn items randomly by doing this:
Code:
integer i = random integer from 0 to index
create item at spawnPoints[i]
Of course you could create your own pseudo-random number generator so that you won't end up with items being spawned way too close to each other.
You could also deindex locations where you spawned items so that you won't spawn two items at same location.