In the game i'm making I need to constantly find objects from a list and then check if it's coordinates are adjacent, there is hundreds of these objects and only 4 of them can be right, is there a better way to do this?
The list is at getMap.getTerrain(x,y);
It's a 2 Dimension int array that holds the dataValue of the object.
int[] r = new int[4];
int tX = (int)(getX()/32);
int tY = (int)(getY()/32);
if((tY > 1) && (tX > 1) && (tY < 39) && (tX < 39))
{
r[0] = getMap().getTerrain(tX-1, tY);
r[1] = getMap().getTerrain(tX+1, tY);
r[2] = getMap().getTerrain(tX, tY-1);
r[3] = getMap().getTerrain(tX, tY+1);
//}
}
int resource = 0;
for(int i : r) if(i != 0) resource = i;
if(resource != 0)
{
System.out.println("R isnt 0, We are next to a "+resource);
}