Example #1
0
 private static void MoveCross(TrainPosition position)
 {
     if ((position.Angle > 45.0f && position.Angle < 135.0f) ||
         (position.Angle > 225.0f && position.Angle < 315.0f))
     {
         TrainMovement.MoveVertical(position);
     }
     else
     {
         TrainMovement.MoveHorizontal(position);
     }
 }
Example #2
0
 private static void MoveRightUpDown(TrainPosition position)
 {
     if ((position.Angle >= 180 && position.Angle <= 90.0) ||
         (position.Angle >= 270 && position.Angle <= 360))
     {
         TrainMovement.MoveRightDown(position);
     }
     else
     {
         TrainMovement.MoveRightUp(position);
     }
 }
Example #3
0
 private static void MoveLeftUpDown(TrainPosition position)
 {
     if (position.RelativeTop < 0.4f)
     {
         TrainMovement.MoveLeftUp(position);
     }
     else if (position.RelativeTop > 0.6f)
     {
         TrainMovement.MoveLeftDown(position);
     }
     else if (TrainMovement.BetweenAngles(position.Angle, 89, 181))
     {
         TrainMovement.MoveLeftUp(position);
     }
     else
     {
         TrainMovement.MoveLeftDown(position);
     }
 }
Example #4
0
 private static void MoveLeftRightUp(TrainPosition position)
 {
     if (position.RelativeLeft < 0.4f)
     {
         TrainMovement.MoveLeftUp(position);
     }
     else if (position.RelativeLeft > 0.6f)
     {
         TrainMovement.MoveRightUp(position);
     }
     else if (TrainMovement.BetweenAngles(position.Angle, 179, 271))
     {
         TrainMovement.MoveRightUp(position);
     }
     else
     {
         TrainMovement.MoveLeftUp(position);
     }
 }
Example #5
0
 private static void MoveLeftRightDown(TrainPosition position)
 {
     // Check single track extremes, as there are 2 places where the
     //  train angle could be at 0 degrees
     if (position.RelativeLeft < 0.4f)
     {
         TrainMovement.MoveLeftDown(position);
     }
     else if (position.RelativeLeft > 0.6f)
     {
         TrainMovement.MoveRightDown(position);
     }
     else if (position.Angle <= 90.0)
     {
         TrainMovement.MoveLeftDown(position);
     }
     else
     {
         TrainMovement.MoveRightDown(position);
     }
 }
Example #6
0
        /// <summary>
        /// Moves a train around a 90 degree arc, in either direction
        /// </summary>
        /// <param name="position">The trains position</param>
        /// <param name="quadrantPositionX">The distance between the center of the circle, and the left hand side of the cell</param>
        /// <param name="quadrantPositionY">The distance between the center of the circle, and the top of the cell</param>
        /// <param name="midpointAngle">The angle at the middle of the arc you want to move</param>
        public static void MoveAroundCorner(TrainPosition position, int quadrantPositionX, int quadrantPositionY, int minTrainAngleCCW, int maxTrainAngleCCW, int minimumAngle, int maximumAngle)
        {
            // Find the angle within the tracks circle using the current position
            // This *should* be perpendicular to angle
            double currentAngle = TrainMovement.PointsToAngle(position.RelativeLeft - Math.Abs(quadrantPositionX), position.RelativeTop - Math.Abs(quadrantPositionY));

            // To travel 2PIr, we need to move 360
            // To travel x we need to move x/2PIr * 360
            // To travel x rad we need to move x/2PIr * 2PI
            // To travel x rad we need to move x/r
            double angleToMove = position.Distance / 0.5;
            float  distance;

            // In order to figure out if we are moving clockwise or counter-clockwise, look at the angle of the train
            if (BetweenAngles(position.Angle, minTrainAngleCCW, maxTrainAngleCCW))
            {
                // We are facing left/up, so we move counter clockwise, with a minimum angle of 90
                (currentAngle, distance) = MoveCounterClockwise(currentAngle, angleToMove, position.Distance, DegreeToRad(minimumAngle));

                position.Angle = (float)TrainMovement.RadToDegree(currentAngle) - 90.0f;
            }
            else
            {
                // We are NOT facing left/up, so we move clockwise, with a maximum angle of 180, Math.PI
                (currentAngle, distance) = MoveClockwise(currentAngle, angleToMove, position.Distance, DegreeToRad(maximumAngle));

                position.Angle = (float)TrainMovement.RadToDegree(currentAngle) + 90.0f;
            }

            position.Distance = distance;

            // Double check to keep our angle in range, this makes our angle checks easier!:
            position.Angle = TrainMovement.KeepWithin0and360(position.Angle);

            // Find our new position on the track
            (position.RelativeLeft, position.RelativeTop) = TrainMovement.AngleToPoints(currentAngle, 0.5f);

            position.RelativeLeft += Math.Abs(quadrantPositionX);
            position.RelativeTop  += Math.Abs(quadrantPositionY);
        }
Example #7
0
        public static void MoveHorizontal(TrainPosition position)
        {
            // Snap top
            position.RelativeTop = 0.5f;

            // Snap angle
            if (position.Angle < 90f || position.Angle > 270f)
            {
                position.Angle = 0f;
                float toGo = 1.0f - position.RelativeLeft;

                if (position.Distance < toGo)
                {
                    position.RelativeLeft += position.Distance;
                    position.Distance      = 0;
                }
                else
                {
                    position.Distance    -= toGo;
                    position.RelativeLeft = 1.1f;
                }
            }
            else
            {
                position.Angle = 180f;
                float toGo = position.RelativeLeft;

                if (position.Distance < toGo)
                {
                    position.RelativeLeft -= position.Distance;
                    position.Distance      = 0;
                }
                else
                {
                    position.Distance    -= toGo;
                    position.RelativeLeft = -0.1f;
                }
            }
        }
Example #8
0
        public static void MoveVertical(TrainPosition position)
        {
            // Snap left
            position.RelativeLeft = 0.5f;

            // Snap angle
            if (position.Angle < 180f)
            {
                position.Angle = 90f;
                float toGo = 1.0f - position.RelativeTop;

                if (position.Distance < toGo)
                {
                    position.RelativeTop += position.Distance;
                    position.Distance     = 0;
                }
                else
                {
                    position.Distance   -= toGo;
                    position.RelativeTop = 1.1f;
                }
            }
            else
            {
                position.Angle = 270f;
                float toGo = position.RelativeTop;

                if (position.Distance < toGo)
                {
                    position.RelativeTop -= position.Distance;
                    position.Distance     = 0;
                }
                else
                {
                    position.Distance   -= toGo;
                    position.RelativeTop = -0.1f;
                }
            }
        }
Example #9
0
 private static void MoveRightUpDown(TrainPosition position)
 {
     // Right -> Up, Enters 180, Leaves 270
     // Up -> Right, Enters 90, Leaves 0
     // Down -> Right, Enters 270, Leaves 0
     if (position.RelativeTop < 0.4f)
     {
         TrainMovement.MoveRightUp(position);
     }
     else if (position.RelativeTop > 0.6f)
     {
         TrainMovement.MoveRightDown(position);
     }
     else if (position.Angle >= 270.0)
     {
         TrainMovement.MoveRightDown(position);
     }
     else
     {
         TrainMovement.MoveRightUp(position);
     }
 }
Example #10
0
 public static void MoveLeftUp(TrainPosition position) => TrainMovement.MoveAroundCorner(position, 0, 0, 225, 45, 0, 90);
Example #11
0
 public static void MoveRightUp(TrainPosition position) => TrainMovement.MoveAroundCorner(position, -1, 0, -45, 135, 90, 180);
Example #12
0
 public static void MoveRightDown(TrainPosition position) => TrainMovement.MoveAroundCorner(position, -1, -1, 45, 225, 180, 270);
Example #13
0
 public static void MoveLeftDown(TrainPosition position) => TrainMovement.MoveAroundCorner(position, 0, -1, 135, 315, 270, 360);
Example #14
0
 public static void MoveLeftDown(TrainPosition position)
 {
     TrainMovement.MoveAroundCorner(position, 0, -1, 135, 315, -90, 0);
 }
Example #15
0
 public static void MoveRightDown(TrainPosition position)
 {
     TrainMovement.MoveAroundCorner(position, -1, -1, 45, 220, -180, 360);
 }