예제 #1
0
    void FindPath()
    {
        TileSystem tileSystem = TileSystem.Instance;

        while (0 != _pathfindingQueue.Count)
        {
            //제일 앞 타일을 하나 꺼낸다.
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);

            //방문한 타일인가?
            if (false == command.tileCell.IsVisit())
            {
                command.tileCell.Visit();

                if (_targetTileCell.GetTilePosition().Equals(command.tileCell.GetTilePosition()))
                {
                    _reverseTileCell = _targetTileCell;
                    return;
                }

                for (int direction = 0; direction < (int)eDirection.MAX; direction++)
                {
                    sTilePosition nextTilePos = new sTilePosition(command.tileCell.GetTileX(), command.tileCell.GetTileY());
                    TileHelper.GetNextTilePosByDirection((eDirection)direction, ref nextTilePos);
                    TileCell nextTileCell = tileSystem.GetTileCell(nextTilePos);

                    if (((true == tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY)) && false == nextTileCell.IsVisit()) ||
                        (nextTilePos.tileX == _targetTileCell.GetTileX() && nextTilePos.tileY == _targetTileCell.GetTileY()))
                    {
                        float newDistanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight();
                        float newHeuristic         = CalcAstarHeuristic(newDistanceFromStart, nextTileCell, _targetTileCell);

                        if (null == nextTileCell.GetPrevCell())
                        {
                            nextTileCell.SetDistanceFromStart(newDistanceFromStart);
                            nextTileCell.SetPrevCell(command.tileCell);                                 //이전 타일 기억

                            sPathCommand newCommand = new sPathCommand();
                            newCommand.heuristic = newHeuristic;
                            newCommand.tileCell  = nextTileCell;
                            PushCommand(newCommand);
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    public List <TileCell> GetTilecellInAttackRange(TileCell startCell, eDirection direction, eAttackRangeType rangeType, int range)
    {
        List <TileCell> tileCells = new List <TileCell>();

        tileCells.Add(startCell);               //캐릭터가 밟고있는 셀을 넣어준다.

        sTilePosition tilePos = startCell.GetTilePosition();

        //STRAIGHT
        for (int i = 0; i < range; i++)
        {
            TileHelper.GetNextTilePosByDirection(direction, ref tilePos);
            TileCell tilecell = GetTileCell(tilePos.tileX, tilePos.tileY);
            if (null != tilecell)
            {
                tileCells.Add(tilecell);
            }
        }

        return(tileCells);
    }