Example #1
0
    //this version get all moore neighbours including walls: is a more general version
    public static Vector2Int[] getAllMooreNeighbours_General(Vector2Int id, ITypeGrid TypeGrid, int width, int height)
    {
        Vector2Int[] results = new Vector2Int[] { };

        foreach (Vector2Int dir in TypeGrid.getDirs())
        {
            Vector2Int next = new Vector2Int(id.x + dir.x, id.y + dir.y);
            if (in_bounds_General(next, width, height))
            {
                Array.Resize(ref results, results.Length + 1);
                results[results.GetUpperBound(0)] = next;
            }
        }

        foreach (Vector2Int dir in TypeGrid.getDiags())
        {
            Vector2Int next = new Vector2Int(id.x + dir.x, id.y + dir.y);
            if (in_bounds_General(next, width, height))
            {
                Array.Resize(ref results, results.Length + 1);
                results[results.GetUpperBound(0)] = next;
            }
        }

        if ((id.x + id.y) % 2 == 0)
        {
            Array.Reverse(results);
        }

        return(results);
    }
Example #2
0
    //this version get all neighbours walls excluded
    public Vector2Int[] getNeighbours(Vector2Int id)
    {
        Vector2Int[] results = new Vector2Int[] { };

        foreach (Vector2Int dir in TypeGrid.getDirs())
        {
            Vector2Int next = new Vector2Int(id.x + dir.x, id.y + dir.y);
            if (in_bounds(next) && passable(next))
            {
                Array.Resize(ref results, results.Length + 1);
                results[results.GetUpperBound(0)] = next;
            }
        }

        if ((id.x + id.y) % 2 == 0)
        {
            Array.Reverse(results);
        }

        return(results);
    }
Example #3
0
    //this version get all neighbours including walls and cells outside the grid: is a more general version
    public static Vector2Int[] getAllNeighboursWOBoundCheck_General(Vector2Int id, ITypeGrid TypeGrid)
    {
        Vector2Int[] results = new Vector2Int[] { };

        foreach (Vector2Int dir in TypeGrid.getDirs())
        {
            Vector2Int next = new Vector2Int(id.x + dir.x, id.y + dir.y);

            Array.Resize(ref results, results.Length + 1);
            results[results.GetUpperBound(0)] = next;
        }

        if ((id.x + id.y) % 2 == 0)
        {
            Array.Reverse(results);
        }

        return(results);
    }