private void GenerateNeighbors() { //0-3 = sides, 4-7 = diagonals //0 = (-1, 0) //1 = (0,-1) //2 = (0,1) //3 = (1,0) //4 = (-1,-1) //5 = (-1,1) //6 = (1,-1) //7 = (1,1) int sideIndex = 0; int diagonalIndex = 4; //I learned how to spell [s]diagnal[/s] diagonal!!! for (i = -1; i <= 1; i++) { checkX = gridX + i; for (j = -1; j <= 1; j++) { if (i == 0 && j == 0) //Don't do anything for the same node { continue; } checkY = gridY + j; if (GridManager.ValidateCoordinates(checkX, checkY)) { int neighborIndex; if ((i != 0 && j != 0)) { //Diagonal if (GridManager.UseDiagonalConnections) { neighborIndex = diagonalIndex++; } else { continue; } } else { neighborIndex = sideIndex++; } GridNode checkNode = GridManager.Grid [GridManager.GetGridIndex(checkX, checkY)]; NeighborNodes [neighborIndex] = checkNode; } } } }