Ejemplo n.º 1
0
        public static PathSegment createSegmentFromPath(List<Tile> openList)
        {
            //define a segment from the provided path.

            Tile parentTile = openList[0];
            List<Tile> segmentTiles = new List<Tile>();
            segmentTiles.Add(parentTile);
            bool xSegment = false;
            bool ySegment = false;

            //first find out if this is a segment with linearity in x or y
            if (openList[1].xPos == parentTile.xPos)
            {
                xSegment = true;
            }
            else if (openList[1].yPos == parentTile.yPos)
            {
                ySegment = true;
            }

            for( int i = 1; i < openList.Count; i++)
            {
                Tile tile = openList[i];

                if (xSegment)
                {
                    if (tile.xPos == parentTile.xPos)
                    {
                        //this is an xSegment, and the next tile is the same in x - add it to the segmentTiles!
                        segmentTiles.Add(tile);
                    }
                    else
                    {
                        //looks like we're no longer incrementing in x - time to break!
                        break;
                    }
                }
                else if (ySegment)
                {
                    if (tile.yPos == parentTile.yPos)
                    {
                        //this is an ySegment, and the next tile is the same in y - add it to the segmentTiles!
                        segmentTiles.Add(tile);
                    }
                    else
                    {
                        //looks like we're no longer incrementing in y - time to break!
                        break;
                    }
                }

                parentTile = openList[i];

            }

            PathSegment returnSegment = new PathSegment(segmentTiles);

            return returnSegment;
        }
Ejemplo n.º 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);
 }