Esempio n. 1
0
 public static string SaveToString(Microsoft.Xna.Framework.Point?point)
 {
     if (point.HasValue)
     {
         return(point.Value.X.ToString() + " " + point.Value.Y.ToString());
     }
     return(string.Empty);
 }
Esempio n. 2
0
 public override void PostDeserializationActions(bool?selected, XNA.Point?offset)
 {
     if (selected.HasValue)
     {
         Selected = selected.Value;
     }
     if (offset.HasValue)
     {
         Move(X + offset.Value.X, Y + offset.Value.Y);
     }
 }
Esempio n. 3
0
 public void PostDeserializationActions(bool?selected, XNA.Point?offset)
 {
     if (selected.HasValue)
     {
         firstAnchor.Selected = secondAnchor.Selected = selected.Value;
     }
     if (offset.HasValue)
     {
         firstAnchor.MoveSilent(firstAnchor.X + offset.Value.X, firstAnchor.Y + offset.Value.Y);
         secondAnchor.MoveSilent(secondAnchor.X + offset.Value.X, secondAnchor.Y + offset.Value.Y);
     }
 }
Esempio n. 4
0
 public virtual void PostDeserializationActions(bool?selected, XNA.Point?offset)
 {
     if (selected.HasValue)
     {
         Selected = selected.Value;
     }
     if (offset.HasValue)
     {
         position.X += offset.Value.X;
         position.Y += offset.Value.Y;
     }
 }
Esempio n. 5
0
 public override void PostDeserializationActions(bool?selected, XNA.Point?offset)
 {
     if (selected.HasValue)
     {
         Selected = selected.Value;
     }
     if (offset.HasValue)
     {
         foreach (MapleDot dot in new[] { a, b, c, d })
         {
             dot.MoveSilent(dot.X + offset.Value.X, dot.Y + offset.Value.Y);
         }
     }
 }
Esempio n. 6
0
        public void DoSnap()
        {
            if (!baseInfo.Connect)
            {
                return;
            }
            XNA.Point?closestDestPoint = null;
            double    closestDistance  = double.MaxValue;

            foreach (LayeredItem li in Board.BoardItems.TileObjs)
            {
                // Trying to snap to other selected items can mess up some of the mouse bindings
                if (!(li is ObjectInstance) || li.Selected || li.Equals(this))
                {
                    continue;
                }
                ObjectInstance objInst = (ObjectInstance)li;
                ObjectInfo     objInfo = (ObjectInfo)objInst.BaseInfo;
                if (!objInfo.Connect)
                {
                    continue;
                }
                XNA.Point snapPoint = new XNA.Point(objInst.X, objInst.Y - objInst.Origin.Y + objInst.Height + this.Origin.Y);
                double    dx        = snapPoint.X - X;
                double    dy        = snapPoint.Y - Y;
                if (dx > UserSettings.SnapDistance || dy > UserSettings.SnapDistance)
                {
                    continue;
                }
                double distance = InputHandler.Distance(dx, dy);
                if (distance > UserSettings.SnapDistance)
                {
                    continue;
                }
                if (closestDistance > distance)
                {
                    closestDistance  = distance;
                    closestDestPoint = snapPoint;
                }
            }

            if (closestDestPoint.HasValue)
            {
                SnapMoveAllMouseBoundItems(new XNA.Point(closestDestPoint.Value.X, closestDestPoint.Value.Y));
            }
        }
Esempio n. 7
0
        public override void DoSnap()
        {
            // Lookup possible snap to foothold
            FootholdLine closestLine         = null;
            double       closestDistanceLine = double.MaxValue;

            foreach (FootholdLine fh in Board.BoardItems.FootholdLines)
            {
                if (fh.FirstDot.Selected || fh.SecondDot.Selected)
                {
                    continue;
                }
                if (!fh.IsWall && BetweenOrEquals(X, fh.FirstDot.X, fh.SecondDot.X, (int)UserSettings.SnapDistance) && BetweenOrEquals(Y, fh.FirstDot.Y, fh.SecondDot.Y, (int)UserSettings.SnapDistance))
                {
                    double targetY  = fh.CalculateY(X) + 2;
                    double distance = Math.Abs(targetY - Y);
                    if (closestDistanceLine > distance)
                    {
                        closestDistanceLine = distance;
                        closestLine         = fh;
                    }
                }
            }

            // Lookup possible snap to rope/ladder
            XNA.Point?closestRopeHint     = null;
            double    closestDistanceRope = double.MaxValue;
            bool      closestIsLadder     = false;

            foreach (LayeredItem li in Board.BoardItems.TileObjs)
            {
                if (!(li is ObjectInstance) || li.Selected)
                {
                    continue;
                }
                ObjectInstance objInst = (ObjectInstance)li;
                ObjectInfo     objInfo = (ObjectInfo)objInst.BaseInfo;
                if (objInfo.RopeOffsets != null)
                {
                    LookupSnapInOffsetMap(objInst, objInfo.RopeOffsets, false, ref closestRopeHint, ref closestDistanceRope, ref closestIsLadder);
                }
                if (objInfo.LadderOffsets != null)
                {
                    LookupSnapInOffsetMap(objInst, objInfo.LadderOffsets, true, ref closestRopeHint, ref closestDistanceRope, ref closestIsLadder);
                }
            }

            if (closestDistanceRope >= closestDistanceLine && closestLine != null)
            {
                // If foothold is closer, snap to it
                SnapMoveAllMouseBoundItems(new XNA.Point(Parent.X + Parent.BoundItems[this].X, (int)closestLine.CalculateY(X) + 2));
            }
            else if (closestDistanceRope <= closestDistanceLine && closestRopeHint.HasValue)
            {
                // If rope/ladder is closer, snap to it and change our rope/ladder policy, unless it was hard-set by the user
                SnapMoveAllMouseBoundItems(new XNA.Point(closestRopeHint.Value.X, closestRopeHint.Value.Y));
                if (!this.parentRope.ladderSetByUser)
                {
                    this.parentRope.ladder = closestIsLadder;
                }
            }
        }
Esempio n. 8
0
 private void LookupSnapInOffsetMap(ObjectInstance objInst, List <List <XNA.Point> > offsetMap, bool ladderList, ref XNA.Point?closestRopeHint, ref double closestDistanceRope, ref bool closestIsLadder)
 {
     foreach (List <XNA.Point> offsetList in offsetMap)
     {
         foreach (XNA.Point offset in offsetList)
         {
             int dx = objInst.X + offset.X - X;
             int dy = objInst.Y + offset.Y - Y;
             if (Math.Abs(dx) > UserSettings.SnapDistance || Math.Abs(dy) > UserSettings.SnapDistance)
             {
                 continue;
             }
             double distance = InputHandler.Distance(dx, dy);
             if (distance > UserSettings.SnapDistance)
             {
                 continue;
             }
             if (closestDistanceRope > distance)
             {
                 closestDistanceRope = distance;
                 closestRopeHint     = new XNA.Point(objInst.X + offset.X, objInst.Y + offset.Y);
                 closestIsLadder     = ladderList;
             }
         }
     }
 }
Esempio n. 9
0
File: Scene.cs Progetto: XF9/Fenrir
        /// <summary>
        /// computes the shortest route to a given set of possible points .. if reachable
        /// </summary>
        /// <param name="currentPosition">the start position</param>
        /// <param name="targets">the positions you want to get to</param>
        /// <returns></returns>
        public LinkedList <Microsoft.Xna.Framework.Point> getPath(Microsoft.Xna.Framework.Point currentPosition, List <Microsoft.Xna.Framework.Point> targets)
        {
            foreach (Microsoft.Xna.Framework.Point target in targets)
            {
                if (currentPosition == target)
                {
                    return(new LinkedList <Microsoft.Xna.Framework.Point>());
                }
            }


            // Breadth-First-Search / Distance Table
            // this will give us the perfect route

            Boolean foundTarget = false;
            Dictionary <Microsoft.Xna.Framework.Point, int> distanceMap = new Dictionary <Microsoft.Xna.Framework.Point, int>();

            Microsoft.Xna.Framework.Point?targetTile = null;

            List <Microsoft.Xna.Framework.Point> neighboursCurrent = new List <Microsoft.Xna.Framework.Point>(); // neighbours, checkt in the current iteration
            List <Microsoft.Xna.Framework.Point> neighboursNext    = new List <Microsoft.Xna.Framework.Point>(); // neighbours, checkt in the next iteration

            int distance = 0;

            Microsoft.Xna.Framework.Point[] pointer = { new Microsoft.Xna.Framework.Point(), new Microsoft.Xna.Framework.Point(), new Microsoft.Xna.Framework.Point(), new Microsoft.Xna.Framework.Point() };
            neighboursCurrent.Add(currentPosition);


            while (!foundTarget)
            {
                foreach (Microsoft.Xna.Framework.Point neighbour in neighboursCurrent)
                {
                    if (!foundTarget && !distanceMap.ContainsKey(neighbour)) // skip if already found or the rare occasion with two or more ways to the same tile with the same amount of steps
                    {
                        distanceMap.Add(neighbour, distance);

                        pointer[2].Y = neighbour.Y;
                        pointer[2].X = neighbour.X - 1;

                        pointer[3].Y = neighbour.Y;
                        pointer[3].X = neighbour.X + 1;

                        pointer[0].Y = neighbour.Y - 1;
                        pointer[0].X = neighbour.X;

                        pointer[1].Y = neighbour.Y + 1;
                        pointer[1].X = neighbour.X;

                        foreach (Microsoft.Xna.Framework.Point possibleMovement in pointer)
                        {
                            Components.TileState state = FenrirGame.Instance.InGame.Scene.GetBlockState(possibleMovement);
                            if ((state == Components.TileState.Walkable || state == Components.TileState.Climbable) && !distanceMap.ContainsKey(possibleMovement))
                            {
                                neighboursNext.Add(possibleMovement);
                            }

                            // check if a target
                            foreach (Microsoft.Xna.Framework.Point target in targets)
                            {
                                if (possibleMovement.X == target.X && possibleMovement.Y == target.Y)
                                {
                                    foundTarget = true;
                                    targetTile  = target;
                                }
                            }
                        }
                    }
                }

                distance++;
                neighboursCurrent = new List <Microsoft.Xna.Framework.Point>(neighboursNext);
                neighboursNext.Clear();

                // if we have no next neighbours left to check and still havent found the target there is no way
                if (neighboursCurrent.Count == 0)
                {
                    foundTarget = true;
                }
            }

            // if the current block is the one to be mined error is set too
            // so check if me might found the target
            if (!targetTile.HasValue)
            {
                FenrirGame.Instance.Log(LogLevel.Error, "unreachable target for pathfinding");
                return(null);
            }
            else
            {
                // samething backwards - search the path
                foundTarget = false;
                LinkedList <Microsoft.Xna.Framework.Point> path = new LinkedList <Microsoft.Xna.Framework.Point>();
                Microsoft.Xna.Framework.Point moveTo            = targetTile.Value;
                Boolean foundSmallerOne;
                path.AddFirst(targetTile.Value);

                while (!foundTarget)
                {
                    pointer[0].Y = targetTile.Value.Y;
                    pointer[0].X = targetTile.Value.X - 1;

                    pointer[1].Y = targetTile.Value.Y;
                    pointer[1].X = targetTile.Value.X + 1;

                    pointer[2].Y = targetTile.Value.Y - 1;
                    pointer[2].X = targetTile.Value.X;

                    pointer[3].Y = targetTile.Value.Y + 1;
                    pointer[3].X = targetTile.Value.X;

                    foundSmallerOne = false;

                    foreach (Microsoft.Xna.Framework.Point possibleMovement in pointer)
                    {
                        int blockDistance;
                        if (distanceMap.TryGetValue(possibleMovement, out blockDistance))
                        {
                            if (blockDistance < distance && blockDistance > 0)
                            {
                                foundSmallerOne = true;
                                distance        = blockDistance;
                                moveTo          = possibleMovement;
                            }
                        }
                    }

                    if (foundSmallerOne)
                    {
                        path.AddFirst(moveTo);
                        targetTile = moveTo;
                    }
                    else
                    {
                        foundTarget = true;
                    }
                }

                return(path);
            }
        }
Esempio n. 10
0
 public void PostDeserializationActions(bool?selected, XNA.Point?offset)
 {
     // Nothing to do here, we cant be offset nor selected.
 }