Exemple #1
0
 public void Setup(int _x, int _y)
 {
     if (_x < 0 || _y < 0)
     {
         Debug.LogError("Cannot be negative!");
     }
     gridX      = _x;
     gridY      = _y;
     gridIndex  = GridManager.GetGridIndex(gridX, gridY);
     WorldPos.x = gridX * FixedMath.One + GridManager.OffsetX;
     WorldPos.y = gridY * FixedMath.One + GridManager.OffsetY;
 }
Exemple #2
0
        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;
                    }
                }
            }
        }