Exemplo n.º 1
0
        private bool IsNullTileReadyToVisible(int x, int y)
        {
            if (!grid.CellIsValid(x, y))
            {
                return(false);
            }

            if (LevelManager.Main.Grid.GetTile(x, y) != Element.NULL || grid.GetTile(x, y) != TileVisibility.Invisible)
            {
                return(grid.GetTile(x, y) != TileVisibility.ReadyToVisible);
            }

            if (showDebugLog.HasFlag(LevelFogDebug.ReadyToVisible_Logic))
            {
                Debug.Log($"Is Tile {x},{y} ReadyToVisible?");
            }

            bool isReadyToVisible = true;

            Element        type;
            TileVisibility visibility;

            List <Vector2Int> neighbours = grid.GatherNeighbourCells(x, y, 1, true, true);
            Vector2Int        neighbour;

            for (int i = 0; i < neighbours.Count && isReadyToVisible; i++)
            {
                neighbour = neighbours[i];

                if (!LevelManager.Main.Grid.CellIsValid(neighbour.x, neighbour.y))
                {
                    continue;
                }

                if (!grid.CellIsValid(neighbour.x, neighbour.y))
                {
                    continue;
                }

                type             = LevelManager.Main.Grid.GetTile(neighbour.x, neighbour.y);
                visibility       = grid.GetTile(neighbour.x, neighbour.y);
                isReadyToVisible = visibility == TileVisibility.Visible || type == Element.NULL;
                if (showDebugLog.HasFlag(LevelFogDebug.ReadyToVisible_Logic))
                {
                    Debug.Log($"Checked neighbour {x},{y} ({visibility}) => {isReadyToVisible}");
                }
            }

            if (isReadyToVisible)
            {
                grid.SetTile(x, y, TileVisibility.ReadyToVisible);
            }

            return(isReadyToVisible);
        }
Exemplo n.º 2
0
    private static List <PathNode> GetNeighbourList(PathNode currentNode)
    {
        List <PathNode> neighbourList        = new List <PathNode>();
        Direction       currentNodeDirection = gridElements.GetTile(currentNode.GetCell()).ToDirection();

        if (currentNodeDirection != Direction.NULL && currentNodeDirection != Direction.All)
        {
            Vector2Int cellFaced = currentNode.GetCell() + currentNodeDirection.ToOffset();
            if (grid.CellIsValid(cellFaced))
            {
                neighbourList.Add(grid.GetTile(cellFaced));
            }
        }
        else
        {
            //Left
            if (grid.CellIsValid(currentNode.X - 1, currentNode.Y))
            {
                neighbourList.Add(grid.GetTile(currentNode.X - 1, currentNode.Y));
            }

            // Right
            if (grid.CellIsValid(currentNode.X + 1, currentNode.Y))
            {
                neighbourList.Add(grid.GetTile(currentNode.X + 1, currentNode.Y));
            }

            // Up
            if (grid.CellIsValid(currentNode.X, currentNode.Y - 1))
            {
                neighbourList.Add(grid.GetTile(currentNode.X, currentNode.Y - 1));
            }

            // Down
            if (grid.CellIsValid(currentNode.X, currentNode.Y + 1))
            {
                neighbourList.Add(grid.GetTile(currentNode.X, currentNode.Y + 1));
            }
        }

        if (!includeNullElements)
        {
            neighbourList = neighbourList.Where(p => gridElements.GetTile(p.GetCell()) != Element.NULL).ToList();
        }

        return(neighbourList);
    }