/*Character movement path is a set of tiles broken into linear segments
         * One path is made of 1 to N linear segments.
         * Path object is a List of Tile Lists
         * Game loops through Tile Lists and moves the character until there are no more
         * Then we change the char's position to it's destination, change its state, and set the profile to null
         */
        public static void setCharMovement(Character charToMove, List<Tile> optimalPath)
        {
            //using the char and the calcuated path, create a movementPath object.
            //cycle through the tiles on the optimal path.

            bool pathComplete = false; //if yes, we're done
            List<PathSegment> movementPathSegments = new List<PathSegment>();

            List<Tile> closedList = new List<Tile>();

            //prepare the given path for this process - reverse the list!
            optimalPath.Reverse();

            List<Tile> openList = optimalPath;

            while (!pathComplete)
            {
                //pass the openlist into createSegmentFromPath. Add the tiles from the returned segment to the closed list, and remove them from the open list.
                if (openList.Count > 1)
                {
                    PathSegment currentSegment = createSegmentFromPath(openList);

                    for (int i = 0; i < currentSegment.segmentTiles.Count - 1; i++)
                    {
                        Tile tile = currentSegment.segmentTiles[i];
                        closedList.Add(tile);
                        openList.Remove(tile);
                    }

                    movementPathSegments.Add(currentSegment);
                }
                else
                {
                    pathComplete = true;
                }

            }
            MovementPath movementPath = new MovementPath(movementPathSegments);
            MovementProfile charMoveProfile = new MovementProfile(movementPath, movementPath.characterPath[0], charToMove);
            charToMove.movementProfile = charMoveProfile;
            charToMove.state = charState.moveing;
        }
Exemple #2
0
 public MovementProfile(MovementPath moveProfile, PathSegment pathSegment, Character charToMove)
 {
     currentpath = moveProfile;
     currentSegment = pathSegment;
     currentDestination = pathSegment.segmentTiles.Last();
     Vector2 currentDestinationVector = new Vector2(currentDestination.xPos, currentDestination.yPos);
     finalDestination = currentpath.characterPath.Last().segmentTiles.Last();
     Vector2 finalDestinationVector = new Vector2(finalDestination.xPos,finalDestination.yPos);
     currentDestinationPixels = charToMove.getPixelPositionByTilePosition(currentDestinationVector);
     finalDestinationPixels = charToMove.getPixelPositionByTilePosition(finalDestinationVector);
 }