Differntiating between objects of the same class
If you have objects all of one class, how do you differentiate between them? This is the issue: I have a class that generates boxes in a 2D array (class name = Block). Depending on how they interact with their environment, their individual size changes so that there are small boxes (those with a width and depth less than 35 pixels) and larger blocks (those with a width and depth of more than 35 pixels). I want to be able to differentiate between blocks on the basis of their size, albeit all from the same class, so that the smaller blocks, when acceleration is added to them, won’t ‘walk’ into the larger blocks. It seems the larger blocks should have a neighbourhood radius and be should be able to measure any small blocks that come into their radius space. When they do, the smaller blocks must stop moving. This is what I currently have but I can't get this function to work:
float distance(Block [][]grid)
{
for (int i = 0; i < grid.length; ++i)
{
for (int j = 0; j < grid.length; ++j)
{
if (grid[i][j].depth > 35 && grid[i][j].w > 35) // go through the loop for large blocks
{
for (int m = 0; m < grid.length; ++m)
{
for (int n = 0; n < grid.length; ++n)
{
if (grid[m][n].h == 35 && grid[m][n].depth == 35 && grid[m][n].w == 35) // go through the loop for smaller blocks
{
distanceBlock = PVector.dist(grid[i][j].pos, grid[m][n].pos);
}
}
}
}
}
}
return distanceBlock;
}
Perhaps I need to look into an id or serial number for each block rather than the strategy outlined above. I've been working on this sketch for some time and any suggestions as how to solve this issue would be greatly appreciated.