Esempio n. 1
0
    protected void SettingMovePossibleTiles()
    {
        TileMap map = GameManager.Instance.GetMap();

        map.ResetVisit(_character);

        TileCell startTileCell = map.GetTileCell(_character.GetTileX(), _character.GetTileY());

        startTileCell.SetPrevTileCell(_character, null);
        sTileHeuristicInfo startCmd;

        startCmd.tileCell  = startTileCell;
        startCmd.heuristic = 0.0f;
        _tileInfoQueue.Add(startCmd);

        while (0 != _tileInfoQueue.Count)
        {
            sTileHeuristicInfo command = _tileInfoQueue[0];
            _tileInfoQueue.RemoveAt(0);
            //가져온 커맨드의 현재 타일셀 방문 표시
            if (false == command.tileCell.IsVisited(_character))
            {
                if (_character.GetMoveRange() == command.tileCell.GetDistanceFromStart(_character))
                {
                    _tileInfoQueue.Clear();
                    return;
                }
                command.tileCell.SetVisit(_character, true);
                _movePossibleTiles.Add(command.tileCell);

                //4방향 next타일들 검사
                for (int direction = (int)eMoveDirection.LEFT; direction < (int)eMoveDirection.DOWN + 1; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = _character.GetPositionByDirection(curPosition, direction);

                    TileCell nextTileCell = map.GetTileCell(nextPosition.x, nextPosition.y);
                    // nextTileCell 방문 안했고, 움직일수 있는 타일일때
                    if (null != nextTileCell && true == nextTileCell.IsPathfindable() && false == nextTileCell.IsVisited(_character))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart(_character) + nextTileCell.GetDistanceFromWeight();
                        float heuristic         = distanceFromStart;

                        if (null == nextTileCell.GetPrevTileCell(_character) || distanceFromStart < nextTileCell.GetDistanceFromStart(_character))
                        {
                            nextTileCell.SetDistanceFromStart(_character, distanceFromStart);
                            nextTileCell.SetPrevTileCell(_character, command.tileCell);

                            sTileHeuristicInfo nextCommand;
                            nextCommand.tileCell  = nextTileCell;
                            nextCommand.heuristic = heuristic;
                            PushSortmoveRangeQueue(nextCommand);
                        }
                    }
                }
            }
        }
    }
Esempio n. 2
0
 void PushSortmoveRangeQueue(sTileHeuristicInfo command)
 {
     _tileInfoQueue.Add(command);
     _tileInfoQueue.Sort(delegate(sTileHeuristicInfo cmd, sTileHeuristicInfo nextCmd)
     {
         return(cmd.heuristic.CompareTo(nextCmd.heuristic));
     });
 }