Пример #1
0
        public static bool goingToBeAtOrPastPoint(Vector2 currentPosition, Vector2 target, ref Vector2 delta, out Vector2 distanceMinusTarget,
                                                  out Vector2 positiveDelta)
        {
            bool goingToBeAtOrPast = false;
            // for this calculation to see if we are at the target, we need to work with positive only numbers
            float y = delta.Y;
            float x = delta.X;

            if (delta.Y < 0)
            {
                y = -y;
            }
            if (delta.X < 0)
            {
                x = -x;
            }
            positiveDelta = new Vector2(x, y);

            Vector2 minVector, maxVector;

            PositionUtils.getMinMax(target, currentPosition, out minVector, out maxVector);
            distanceMinusTarget = Vector2.Subtract(maxVector, minVector);
            if (x >= distanceMinusTarget.X && y >= distanceMinusTarget.Y)
            {
                goingToBeAtOrPast = true;
            }

            return(goingToBeAtOrPast);
        }
Пример #2
0
        public static void handleChildMovement(float distance, ref Vector2 heading, ref Vector2 position, ref float rotation, ref List <TargetPosition> targetPositions)
        {
            Vector2 delta = PositionUtils.getDelta(heading, distance);
            Vector2 distanceMinusTarget, minVector, maxVector, positiveDelta;

            if (targetPositions != null && targetPositions.Count > 0 && goingToBeAtOrPastPoint(position, targetPositions[0].Position, ref delta, out distanceMinusTarget, out positiveDelta))
            {
                TargetPosition targetPosition = targetPositions[0];
                Type           type           = targetPosition.GetType();
                if (type == typeof(WarpCoordinates))
                {
                    PositionUtils.getMinMax(positiveDelta, distanceMinusTarget, out minVector, out maxVector);
                    Vector2 deltaMinusTargetDistance = Vector2.Subtract(maxVector, minVector);

                    // we need to apply the remainder to the new direction
                    position = ((WarpCoordinates)targetPosition).WarpTo;
                    if (heading == Constants.HEADING_DOWN || heading == Constants.HEADING_UP)
                    {
                        delta    = PositionUtils.getDelta(heading, deltaMinusTargetDistance.Y);
                        position = new Vector2(position.X, position.Y + delta.Y);
                    }
                    else if (heading == Constants.HEADING_LEFT || heading == Constants.HEADING_RIGHT)
                    {
                        delta    = PositionUtils.getDelta(heading, deltaMinusTargetDistance.X);
                        position = new Vector2(position.X + delta.X, position.Y);
                    }
                }
                else if (type == typeof(PivotPoint))
                {
                    PivotPoint pivotPoint = ((PivotPoint)targetPosition);
                    // we are either at or going to pass through the pivot point so we need to set to pivot point + the extra distance
                    PositionUtils.getMinMax(positiveDelta, distanceMinusTarget, out minVector, out maxVector);
                    Vector2 deltaMinusPivotDistance = Vector2.Subtract(maxVector, minVector);

                    // we need to apply the remainder to the new direction
                    position = pivotPoint.Position;
                    if (heading == Constants.HEADING_DOWN || heading == Constants.HEADING_UP)
                    {
                        delta    = PositionUtils.getDelta(pivotPoint.Heading, deltaMinusPivotDistance.Y);
                        position = new Vector2(position.X + delta.X, position.Y);
                    }
                    else if (heading == Constants.HEADING_LEFT || heading == Constants.HEADING_RIGHT)
                    {
                        delta    = PositionUtils.getDelta(pivotPoint.Heading, deltaMinusPivotDistance.X);
                        position = new Vector2(position.X, position.Y + delta.Y);
                    }
                    rotation += MathHelper.ToRadians(pivotPoint.Rotation);
                    heading   = pivotPoint.Heading;
                }
                targetPositions.RemoveAt(0);
            }
            else
            {
                position += delta;
            }
        }