I have a grid that is declared like:
PlayerStatus enum
{
OCCUPIED,
VACANT
}
PlayerStatus[][] grid_ = new PlayerStatus[200][200];
The grid is set equal to all vacant except where players located at.
I would like to have a method that tells me if a player is in a certain grid proximity of another player, something like:
boolean inRange(int x, int y, int range)
{
//This method finds if a player is close to another one
}
So if I pass into inRange(10, 15, 5) and at 10, 19 there is a player I would like the method to return true; where as 10, 21 would return false.
Are there any algorithms that do this kind of searching that I could look into? Or does anyone have any solutions? I feel that calculating diagonals and such will be rather hard, what should I do for that? Any help is appreciated.
Math.hypot()is a good choice for implementing the Pythagorean theorem. There’s an example here namednorm(), which is used in thisKineticModel.