Пример #1
0
    private void TraversePath()
    {
        //Stop patrons from standing inside each other
        if (grid.IsTileFree(path[pathIndex + 1]))
        {
            pathIndex++;
            if (pathIndex >= path.Length)
            {
                pathIndex = path.Length - 1;
            }
            if (pathIndex == path.Length - 1)
            {
                atTable = true;
            }
            grid.Taketile(path[pathIndex], path[pathIndex - 1]);

            transform.position = grid.GetWorldPositionOfGrid(path[pathIndex]);
        }
        else
        {
            waitingForSpace -= secondsPerMove;

            if (waitingForSpace < 0)
            {
                List <Vector2> newPath = pathFinder.GetPath(path[pathIndex], path[path.Length - 1]);
                if (newPath != null)
                {
                    NewPath(newPath);
                }

                waitingForSpace = Random.Range(1f, maxWaitTime);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Gets all the valid neightbors for the current node
    /// </summary>
    /// <param name="current"></param>
    /// <returns></returns>
    List <Vector2> getNeighbors(Vector2 current)
    {
        List <Vector2> neighbors = new List <Vector2>();

        Vector2 neighbor = current;

        neighbor.x++;

        if (grid.IsTileFree(neighbor))
        {
            neighbors.Add(neighbor);
        }

        neighbor = current;
        neighbor.x--;

        if (grid.IsTileFree(neighbor))
        {
            neighbors.Add(neighbor);
        }

        neighbor = current;
        neighbor.y++;

        if (grid.IsTileFree(neighbor))
        {
            neighbors.Add(neighbor);
        }

        neighbor = current;
        neighbor.y--;

        if (grid.IsTileFree(neighbor))
        {
            neighbors.Add(neighbor);
        }

        return(neighbors);
    }