Generate Random Position 2D Grid? (No Overlapping)
Blitz3D Forums/Blitz3D Programming/Generate Random Position 2D Grid? (No Overlapping)| 
 | ||
| I'm looking for a quick solution for a 2D grid to randomly generate X,Y position on a number of items without overlapping. Maybe someone has done this already or posted a code resource somewhere here before. Thanks | 
| 
 | ||
| Keep an array of the same size as the map and store a boolean in each location indicating if youve placed something there already. .. | 
| 
 | ||
| Yes thanks Matty. that was easy per pixel or location but I'm dealing with meshes or squares top down 2D with a random range defined scale. Sorry if I was not being specific. | 
| 
 | ||
| Well then simply write an "overlapping" function that returns a 1/0 and loop through all previous items that have been placed before placing a new one down checking the result of the function. 
function overlapping(a,b)
{
   if(a.x>=b.x and a.y>=b.y and a.x<b.x+b.w and a.y<b.y+b.h) return true;
   if(a.x+a.w>=b.x and a.y+a.h>=b.y and a.x<b.x+b.w and a.y<b.y+b.h) return true;
  return false;
}
 | 
| 
 | ||
| thanks again Matty, I'll check this one out. |