Example #1
0
 public void BuildPathMarker(PathNode newPath)
 {
     ResetPathMarkers();
     m_currentPath = newPath;
     while (newPath != null)
     {
         SetTileColor(newPath.GetNodePosition(), Color.Blue);
         newPath = newPath.GetNextNode();
     }
 }
Example #2
0
        public void ResetPathMarkers()
        {
            if (m_currentPath == null)
                return;

            while (m_currentPath != null)
            {
                SetTileColor(m_currentPath.GetNodePosition(), Color.White);
                m_currentPath = m_currentPath.GetNextNode();
            }
        }
 public void SetCurrentPath(PathNode path)
 {
     m_pnCurrPath = path;
 }
        /// <summary>
        /// This method attempts to plot a path between the startPosition and the endPosition.
        /// If a path is found,  the method returns true and the destPos contains the position
        /// of the first node in the path list.
        /// </summary>
        /// <param name="startPosition">X,Y coordinates of the start position in pixels.</param>
        /// <param name="endPosition">X,Y coordinates of the end position in pixels.</param>
        /// <param name="destPos">X,Y coordinates of the first path node position in pixels, if one is found.</param>
        /// <returns>True if a path is found.</returns>
        public bool FindPathToDestination(Vector2 startPosition, Vector2 endPosition, out Vector2 destPos)
        {
            Vector2 startIndex = Map.MapHandler.GetInstance().GetTileIndex(startPosition);
            Vector2 endIndex = Map.MapHandler.GetInstance().GetTileIndex(endPosition);

            Vector2 closestSoFar = endIndex;
            // Check if the destination is solid
            bool isDestSolid = MapHandler.GetInstance().IsTileSolid(endIndex);
            if (isDestSolid)
            {
                List<Vector2> adj = MapHandler.GetInstance().GetAdjacentsToTile(endIndex);
                if (adj != null && adj.Count>0)
                {
                    closestSoFar = adj[0];
                    foreach (Vector2 vec in adj)
                    {
                        if (!MapHandler.GetInstance().IsTileSolid(vec))
                        {
                            // Find the closest adjecent to the caller.
                            if (Vector2.Distance(closestSoFar, startIndex) > Vector2.Distance(vec, startIndex))
                            {
                                closestSoFar = vec;
                            }
                            //endIndex = vec;
                            //break;
                        }
                    }
                }
            }
            endIndex = closestSoFar;
            // Call Pathfinder find a path from the startIndex to the end index.
            m_pnCurrPath = m_pfMyPathFinder.FindPath(startIndex, endIndex);

            // If a path was found, then make the first node in the
            // path the first destination of this entity.
            if (m_pnCurrPath != null)
            {
                 destPos = Map.MapHandler.GetInstance().GetTilePosition(m_pnCurrPath.GetNodePosition());

                 return true;
                //base.MoveTo(targetPos);
            }
            destPos = Vector2.Zero;
            return false ;
        }
        public GoblinLumberjack(ENTITY_COLOR color)
        {
            m_myColor = color;
            m_SpriteSize = new Vector2(64, 64);
            LoadAnimations("");
            m_MyStateMachine = new StateMachine<GoblinLumberjack>(this);
            m_MyStateMachine.ChangeState(GLumberjack_IDLE.GetInstance());

            #endregion

            // Initialize the Pathfindr
            m_pfMyPathFinder = new AStarPathFinder();
            m_pnCurrPath = null;
            m_EntitySpeed = new Vector2(1, 1);

            #region Nothing to see here, Move along.
        }
 public void SetPrevNode(PathNode prev)
 {
     m_asnPrev = prev;
 }
 public void SetNextNode(PathNode next)
 {
     m_asnNext = next;
 }