示例#1
0
 public virtual bool moveTo(Tile a_tile)
 {
     if (m_moveQueue.Count == 0)
     {
         m_moveQueue = ((GameState)Game.getInstance().getCurrentState()).m_pathFinder.findPath(m_currentPosition.getMapPosition(), a_tile.getMapPosition());
     }
     return(true);
 }
示例#2
0
文件: AStar.cs 项目: Joxe/TacticsRPG
 public static Stack<Tile> reconstructPath(Dictionary<Tile, Tile> a_cameFrom, Tile a_currentNode, Stack<Tile> a_workingList)
 {
     if (a_currentNode.getMapPosition() != a_cameFrom[a_currentNode].getMapPosition()) {
         a_workingList.Push(a_cameFrom[a_currentNode]);
         return reconstructPath(a_cameFrom, a_cameFrom[a_currentNode], a_workingList);
     } else {
         return a_workingList;
     }
 }
示例#3
0
文件: AStar.cs 项目: Joxe/TacticsRPG
 public static Stack <Tile> reconstructPath(Dictionary <Tile, Tile> a_cameFrom, Tile a_currentNode, Stack <Tile> a_workingList)
 {
     if (a_currentNode.getMapPosition() != a_cameFrom[a_currentNode].getMapPosition())
     {
         a_workingList.Push(a_cameFrom[a_currentNode]);
         return(reconstructPath(a_cameFrom, a_cameFrom[a_currentNode], a_workingList));
     }
     else
     {
         return(a_workingList);
     }
 }
示例#4
0
 public void faceTile(Tile a_tile)
 {
     if (a_tile.getMapPosition().X < m_currentPosition.getMapPosition().X)
     {
         if (MathManager.isEven((int)m_currentPosition.getMapPosition().X))
         {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                                         ? m_facingState = FacingState.TopLeft
                                         : m_facingState = FacingState.BottomLeft;
         }
         else
         {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                                         ? m_facingState = FacingState.BottomLeft
                                         : m_facingState = FacingState.TopLeft;
         }
     }
     else if (a_tile.getMapPosition().X > m_currentPosition.getMapPosition().X)
     {
         if (MathManager.isEven((int)m_currentPosition.getMapPosition().X))
         {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                                         ? m_facingState = FacingState.TopRight
                                         : m_facingState = FacingState.BottomRight;
         }
         else
         {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                                         ? m_facingState = FacingState.BottomRight
                                         : m_facingState = FacingState.TopRight;
         }
     }
     else
     {
         m_facingState = a_tile.getMapPosition().Y < m_currentPosition.getMapPosition().Y
                                 ? m_facingState = FacingState.Up
                                 : m_facingState = FacingState.Down;
     }
 }
示例#5
0
文件: AStar.cs 项目: Joxe/TacticsRPG
 private static double getPathValue(Tile a_curTile, Tile a_endTile)
 {
     return(Math.Sqrt(Math.Pow(a_curTile.getMapPosition().X - a_endTile.getMapPosition().X, 2) + Math.Pow(a_curTile.getMapPosition().Y - a_endTile.getMapPosition().Y, 2)));
 }
示例#6
0
文件: AStar.cs 项目: Joxe/TacticsRPG
        private static Stack <Tile> findPath(Tile a_startTile, Tile a_endTile)
        {
            TileMap l_tileMap = ((GameState)Game.getInstance().getCurrentState()).getTileMap();
            Dictionary <Tile, double> l_closedSet = new Dictionary <Tile, double>();
            Dictionary <Tile, double> l_openSet   = new Dictionary <Tile, double>();
            Dictionary <Tile, Tile>   l_cameFrom  = new Dictionary <Tile, Tile>();

            Tile l_neighbor;

            int[] Xcheck = new int[] { 0 };
            int[] Ycheck = new int[] { 0 };

            l_openSet.Add(a_startTile, getPathValue(a_startTile, a_endTile));
            l_cameFrom.Add(a_startTile, a_startTile);

            while (l_openSet.Count > 0)
            {
                KeyValuePair <Tile, double> l_current = l_openSet.First();

                foreach (KeyValuePair <Tile, double> l_kvPair in l_openSet)
                {
                    if (l_kvPair.Value < l_current.Value)
                    {
                        l_current = l_kvPair;
                    }
                }

                if (l_current.Key.getMapPosition() == a_endTile.getMapPosition())
                {
                    Stack <Tile> l_reconstructedPath = new Stack <Tile>();
                    l_reconstructedPath.Push(l_current.Key);
                    return(reconstructPath(l_cameFrom, l_current.Key, l_reconstructedPath));
                }

                l_openSet.Remove(l_current.Key);
                l_closedSet.Add(l_current.Key, l_current.Value);

                if (MathManager.isEven(l_current.Key.X))
                {
                    Xcheck = new[] { -1, 0, 1, 1, 0, -1 };
                    Ycheck = new[] { 1, -1, 0, 1, 1, 0 };
                }
                else
                {
                    Xcheck = new[] { 1, 0, 1, -1, 0, -1 };
                    Ycheck = new[] { -1, -1, 0, -1, 1, 0 };
                }

                for (int i = 0; i < Xcheck.Length && i < Ycheck.Length; i++)
                {
                    int l_newX = (int)l_current.Key.getMapPosition().X + Xcheck[i];
                    int l_newY = (int)l_current.Key.getMapPosition().Y + Ycheck[i];

                    l_neighbor = l_tileMap.getTile(l_newX, l_newY);

                    if (l_neighbor != null)
                    {
                        //int l_heightDifference = l_current.Key.p_height + l_neighbor.p_height;
                        if (l_closedSet.ContainsKey(l_neighbor) || l_neighbor.isObstructed())
                        {
                            continue;
                        }

                        double l_tentativeGScore = l_current.Value + getPathValue(l_neighbor, a_endTile) /* + l_heightDifference*/;

                        if (!l_openSet.ContainsKey(l_neighbor) || l_tentativeGScore < l_openSet[l_neighbor])
                        {
                            l_openSet[l_neighbor]  = l_tentativeGScore;
                            l_cameFrom[l_neighbor] = l_current.Key;
                        }
                    }
                }
            }
            return(new Stack <Tile>());
        }
示例#7
0
 public Tile getTile(Tile a_tile, Vector2 a_mapOffset)
 {
     return getTile((int)(a_tile.getMapPosition().X + a_mapOffset.X), (int)(a_tile.getMapPosition().Y + a_mapOffset.Y));
 }
示例#8
0
 public void faceTile(Tile a_tile)
 {
     if (a_tile.getMapPosition().X < m_currentPosition.getMapPosition().X) {
         if (MathManager.isEven((int)m_currentPosition.getMapPosition().X)) {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                 ? m_facingState = FacingState.TopLeft
                 : m_facingState = FacingState.BottomLeft;
         } else {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                 ? m_facingState = FacingState.BottomLeft
                 : m_facingState = FacingState.TopLeft;
         }
     } else if (a_tile.getMapPosition().X > m_currentPosition.getMapPosition().X) {
         if (MathManager.isEven((int)m_currentPosition.getMapPosition().X)) {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                 ? m_facingState = FacingState.TopRight
                 : m_facingState = FacingState.BottomRight;
         } else {
             m_facingState = a_tile.getMapPosition().Y == m_currentPosition.getMapPosition().Y
                 ? m_facingState = FacingState.BottomRight
                 : m_facingState = FacingState.TopRight;
         }
     } else {
         m_facingState = a_tile.getMapPosition().Y < m_currentPosition.getMapPosition().Y
             ? m_facingState = FacingState.Up
             : m_facingState = FacingState.Down;
     }
 }
示例#9
0
 public virtual bool moveTo(Tile a_tile)
 {
     if (m_moveQueue.Count == 0) {
         m_moveQueue = ((GameState)Game.getInstance().getCurrentState()).m_pathFinder.findPath(m_currentPosition.getMapPosition(), a_tile.getMapPosition());
     }
     return true;
 }
示例#10
0
文件: AStar.cs 项目: Joxe/TacticsRPG
 private static double getPathValue(Tile a_curTile, Tile a_endTile)
 {
     return Math.Sqrt(Math.Pow(a_curTile.getMapPosition().X - a_endTile.getMapPosition().X, 2) + Math.Pow(a_curTile.getMapPosition().Y - a_endTile.getMapPosition().Y, 2));
 }
示例#11
0
文件: AStar.cs 项目: Joxe/TacticsRPG
        private static Stack<Tile> findPath(Tile a_startTile, Tile a_endTile)
        {
            TileMap l_tileMap = ((GameState)Game.getInstance().getCurrentState()).getTileMap();
            Dictionary<Tile, double> l_closedSet	= new Dictionary<Tile, double>();
            Dictionary<Tile, double> l_openSet		= new Dictionary<Tile, double>();
            Dictionary<Tile, Tile> l_cameFrom		= new Dictionary<Tile, Tile>();

            Tile l_neighbor;

            int[] Xcheck = new int[] { 0 };
            int[] Ycheck = new int[] { 0 };

            l_openSet.Add(a_startTile, getPathValue(a_startTile, a_endTile));
            l_cameFrom.Add(a_startTile, a_startTile);

            while (l_openSet.Count > 0) {
                KeyValuePair<Tile, double> l_current = l_openSet.First();

                foreach (KeyValuePair<Tile, double> l_kvPair in l_openSet) {
                    if (l_kvPair.Value < l_current.Value) {
                        l_current = l_kvPair;
                    }
                }

                if (l_current.Key.getMapPosition() == a_endTile.getMapPosition()) {
                    Stack<Tile> l_reconstructedPath = new Stack<Tile>();
                    l_reconstructedPath.Push(l_current.Key);
                    return reconstructPath(l_cameFrom, l_current.Key, l_reconstructedPath);
                }

                l_openSet.Remove(l_current.Key);
                l_closedSet.Add(l_current.Key, l_current.Value);

                if (MathManager.isEven(l_current.Key.X)) {
                    Xcheck = new[] { -1,  0,  1,  1,  0, -1 };
                    Ycheck = new[] {  1, -1,  0,  1,  1,  0 };
                } else {
                    Xcheck = new[] {  1,  0,  1, -1,  0, -1 };
                    Ycheck = new[] { -1, -1,  0, -1,  1,  0 };
                }

                for (int i = 0; i < Xcheck.Length && i < Ycheck.Length; i++) {
                    int l_newX = (int)l_current.Key.getMapPosition().X + Xcheck[i];
                    int l_newY = (int)l_current.Key.getMapPosition().Y + Ycheck[i];

                    l_neighbor = l_tileMap.getTile(l_newX, l_newY);

                    if (l_neighbor != null) {
                        //int l_heightDifference = l_current.Key.p_height + l_neighbor.p_height;
                        if (l_closedSet.ContainsKey(l_neighbor) || l_neighbor.isObstructed()) {
                            continue;
                        }

                        double l_tentativeGScore = l_current.Value + getPathValue(l_neighbor, a_endTile)/* + l_heightDifference*/;

                        if (!l_openSet.ContainsKey(l_neighbor) || l_tentativeGScore < l_openSet[l_neighbor]) {
                            l_openSet[l_neighbor] = l_tentativeGScore;
                            l_cameFrom[l_neighbor] = l_current.Key;
                        }
                    }
                }
            }
            return new Stack<Tile>();
        }
示例#12
0
 public override bool moveTo(Tile a_tile)
 {
     if (m_moveQueue.Count == 0)
     {
         if ((m_moveQueue = ((GameState)Game.getInstance().getCurrentState()).m_pathFinder.findPath(m_currentPosition.getMapPosition(), a_tile.getMapPosition())).Count > m_stats["MoveLeft"] + 1)
         {
             m_moveQueue.Clear();
         }
         else
         {
             m_hasMoved           = true;
             m_stats["MoveLeft"] -= m_moveQueue.Count - 1;
             p_speed             += 50;
             return(true);
         }
     }
     return(false);
 }
示例#13
0
 public Tile getTile(Tile a_tile, Vector2 a_mapOffset)
 {
     return(getTile((int)(a_tile.getMapPosition().X + a_mapOffset.X), (int)(a_tile.getMapPosition().Y + a_mapOffset.Y)));
 }