public PathFinding(GridSystem mainGameGrid)
    {
        _gameGrid = mainGameGrid;
        grid      = _gameGrid.MainGameGrid;

        dist = new int[grid.Width, grid.Height];

        /* initiate distance to be INFINITY */
        FillMax(dist, _queue);

        /* intiate the previous cell of every cell to be null */
        prev = new GridSystem.Cell[grid.Width, grid.Height];
        foreach (var e in grid.Entrances)
        {
            _hashpath.Add(e.X, new List <GridSystem.Cell>());
            _initialpath.Add(e.X, new List <GridSystem.Cell>());
        }
    }
Esempio n. 2
0
    void CreateBoardTiles()
    {
        BoardTiles = new Tile[GridWidth, GridHeight];
        GridSystem.Grid gameGrid = GameGridSystem.MainGameGrid;
        foreach (var entrance in gameGrid.Entrances)
        {
            _gmInstance.SearchFlyingPath(entrance.X, entrance.Y);
        }
        Vector3 startPosition = new Vector3(0f, 0f, 0f);

        startPosition.x = 0 - (GridWidth / 2.0f) * TileSize;
        startPosition.y = 0 - (GridHeight / 2.0f) * TileSize;
        startPosition.z = 0f;

        //Create grid
        for (int y = 0; y < GridHeight; ++y)
        {
            for (int x = 0; x < GridWidth; ++x)
            {
                GridSystem.Cell cell = gameGrid.GetCellAt(x, y);

                if (cell.IsEntrance)
                {
                    BoardTiles[x, y] = new Tile(TileEntrance, x, y, TileSize, _boardHolder, startPosition);
                }
                else if (cell.IsExit)
                {
                    BoardTiles[x, y] = new Tile(TileExit, x, y, TileSize, _boardHolder, startPosition);
                }
                else if (cell.IsBlocked)
                {
                    BoardTiles[x, y] = new Tile(TileObstacles, x, y, TileSize, _boardHolder, startPosition);
                }
                else
                {
                    BoardTiles[x, y] = new Tile(TileGound, x, y, TileSize, _boardHolder, startPosition);
                }
            }
        }
    }