Beispiel #1
0
        //TODO use same action for GetBallsBeforeCount and GetHoleForBall
        //TODO Linq can cause bad performance for big collections. THink about optimizations
        private int GetBallsBeforeCount(Field field, TiltDirection direction, Ball ball)
        {
            switch (direction)
            {
            case TiltDirection.North:
                return(field.Balls.Count(x => !x.HoleId.HasValue &&
                                         x.Coordinates.X == ball.Coordinates.X &&
                                         x.Coordinates.Y > ball.Coordinates.Y));

            case TiltDirection.South:
                return(field.Balls.Count(x => !x.HoleId.HasValue &&
                                         x.Coordinates.X == ball.Coordinates.X &&
                                         x.Coordinates.Y < ball.Coordinates.Y));

            case TiltDirection.West:
                return(field.Balls.Count(x => !x.HoleId.HasValue &&
                                         x.Coordinates.Y == ball.Coordinates.Y &&
                                         x.Coordinates.X < ball.Coordinates.X));

            case TiltDirection.East:
            default:
                return(field.Balls.Count(x => !x.HoleId.HasValue &&
                                         x.Coordinates.Y == ball.Coordinates.Y &&
                                         x.Coordinates.X > ball.Coordinates.X));
            }
        }
    private void TiltShip(TiltDirection direction)
    {
        if (direction == TiltDirection.None && tiltAxisStep != 0)
        {
            if (tiltAxisStep < 0)
            {
                tiltAxisStep += 0.2f;
            }
            if (tiltAxisStep > 0)
            {
                tiltAxisStep -= 0.2f;
            }
        }
        else if (direction == TiltDirection.Left && tiltAxisStep > -1.0f)
        {
            tiltAxisStep -= 0.1f;
            if (tiltAxisStep < -1.0f)
            {
                tiltAxisStep = -1.0f;
            }
        }
        else if (direction == TiltDirection.Right && tiltAxisStep < 1.0f)
        {
            tiltAxisStep += 0.1f;
            if (tiltAxisStep > 1.0f)
            {
                tiltAxisStep = 1.0f;
            }
        }

        spaceShip.transform.Rotate(tiltAxisStep * (-tiltAxis) - spaceShip.transform.eulerAngles.x, 0, 0);
    }
Beispiel #3
0
        private Hole GetHoleForBall(Field field, TiltDirection direction, Ball ball)
        {
            switch (direction)
            {
            case TiltDirection.North:
                return(field.Holes.Where(x => !x.BallId.HasValue &&
                                         x.Coordinates.X == ball.Coordinates.X &&
                                         x.Coordinates.Y > ball.Coordinates.Y).
                       OrderBy(x => x.Coordinates.Y).FirstOrDefault());

            case TiltDirection.South:
                return(field.Holes.Where(x => !x.BallId.HasValue &&
                                         x.Coordinates.X == ball.Coordinates.X &&
                                         x.Coordinates.Y < ball.Coordinates.Y).
                       OrderByDescending(x => x.Coordinates.Y).FirstOrDefault());

            case TiltDirection.West:
                return(field.Holes.Where(x => !x.BallId.HasValue &&
                                         x.Coordinates.Y == ball.Coordinates.Y &&
                                         x.Coordinates.X < ball.Coordinates.X).
                       OrderByDescending(x => x.Coordinates.X).FirstOrDefault());

            case TiltDirection.East:
            default:
                return(field.Holes.Where(x => !x.BallId.HasValue &&
                                         x.Coordinates.Y == ball.Coordinates.Y &&
                                         x.Coordinates.X > ball.Coordinates.X).
                       OrderBy(x => x.Coordinates.Y).FirstOrDefault());
            }
        }
Beispiel #4
0
        /// <summary>
        /// Invokes action of an ended tilt with the given tilt direction.
        /// </summary>
        /// <param name="direction">Direction of the ended tilt.</param>
        private static void InvokeEndedTiltAction(TiltDirection direction)
        {
            switch (direction)
            {
            case TiltDirection.RIGHT:
                OnEndedTiltRight?.Invoke();
                break;

            case TiltDirection.LEFT:
                OnEndedTiltLeft?.Invoke();
                break;

            case TiltDirection.FORWARD:
                OnEndedTiltForward?.Invoke();
                break;

            case TiltDirection.BACKWARD:
                OnEndedTiltBackward?.Invoke();
                break;

            case TiltDirection.NONE:
            default:
                break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Invoke ongoing tilt actions dependent on the given direction.
        /// </summary>
        /// <param name="direction">Direction of the tilt</param>
        /// <param name="tiltMovement">Current movement of the device.</param>
        private static void InvokeOngoingTiltDirectionAction(TiltDirection direction, IVectorMovementInputArgs tiltMovement)
        {
            switch (direction)
            {
            case TiltDirection.RIGHT:
                OnOngoingTiltRight?.Invoke(tiltMovement);
                break;

            case TiltDirection.LEFT:
                OnOngoingTiltLeft?.Invoke(tiltMovement);
                break;

            case TiltDirection.FORWARD:
                OnOngoingTiltForward?.Invoke(tiltMovement);
                break;

            case TiltDirection.BACKWARD:
                OnOngoingTiltBackward?.Invoke(tiltMovement);
                break;

            case TiltDirection.NONE:
            default:
                return;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Updates container which tracks ongoing tilts from the previous frame.
 /// </summary>
 /// <param name="ongoingTiltDirection">Currently ongoing tilt direction.</param>
 private static void UpdatePreviousOngoingTilts(TiltDirection ongoingTiltDirection)
 {
     if (!previousTilts.Contains(ongoingTiltDirection))
     {
         previousTilts.Add(ongoingTiltDirection);
     }
 }
        public void Tilt(byte address, TiltDirection direction, byte speedPercent)
        {
            var message = _requestBuilder.Tilt(address, direction, getMovementSpeedValue(speedPercent));

            _logger.LogDebugMessage($"Tilt {direction} @ {speedPercent} speed => {message}");
            _transport.SendMessage(message);
        }
        public override void TiltMove(string VideoSource, TiltDirection Direction, [System.Xml.Serialization.XmlElementAttribute(DataType = "duration")] string Timeout)
        {
            ParametersValidation validation = new ParametersValidation();

            validation.Add(ParameterType.String, "VideoSource", VideoSource);
            validation.Add(ParameterType.OptionalString, "Timeout", Timeout);
            validation.Add(ParameterType.String, "Direction", Direction.ToString());
            ExecuteVoidCommand(validation, ProvisioningServiceTest.TiltMoveTest);
        }
        public PelcoDEMessage Tilt(byte address, TiltDirection direction, byte speed)
        {
            var cmd = direction switch
            {
                TiltDirection.Up => PelcoDEMessageType.TiltUp,
                TiltDirection.Down => PelcoDEMessageType.TiltDown,
                _ => throw new ArgumentOutOfRangeException(nameof(direction), direction, null)
            };

            return(buildPanTiltContinuously(address, cmd, speed));
        }
Beispiel #10
0
        void Move(TiltDirection direction, Speed speed)
        {
            var data = new byte[]
            {
                (byte)(0x80 + Id),
                0x01,
                0x06,
                0x01,
                0x00,
                (byte)speed,
                0x03,
                (byte)direction,
                0xff
            };

            _socket.Send(data);
        }
Beispiel #11
0
        private Action <Ball> GetTiltAction(TiltDirection direction, int fieldSize, int ballsBefore)
        {
            switch (direction)
            {
            case TiltDirection.North:
                return((ball) => ball.Coordinates = new Point(ball.Coordinates.X, fieldSize - 1 - ballsBefore));

            case TiltDirection.South:
                return((ball) => ball.Coordinates = new Point(ball.Coordinates.X, ballsBefore));

            case TiltDirection.West:
                return((ball) => ball.Coordinates = new Point(ballsBefore, ball.Coordinates.Y));

            case TiltDirection.East:
            default:
                return((ball) => ball.Coordinates = new Point(fieldSize - 1 - ballsBefore, ball.Coordinates.Y));
            }
        }
Beispiel #12
0
        private List <Ball> GetBallsOrder(Field field, TiltDirection direction)
        {
            switch (direction)
            {
            case TiltDirection.North:
                return(field.Balls.Where(x => !x.HoleId.HasValue).OrderByDescending(x => x.Coordinates.Y).ToList());

            case TiltDirection.South:
                return(field.Balls.Where(x => !x.HoleId.HasValue).OrderBy(x => x.Coordinates.Y).ToList());

            case TiltDirection.West:
                return(field.Balls.Where(x => !x.HoleId.HasValue).OrderBy(x => x.Coordinates.X).ToList());

            case TiltDirection.East:
            default:
                return(field.Balls.Where(x => !x.HoleId.HasValue).OrderByDescending(x => x.Coordinates.X).ToList());
            }
        }
Beispiel #13
0
        public void Tilt(Field field, TiltDirection direction)
        {
            // To check ball-hole collision in correct order for balls in same row\column
            var sortedBalls = GetBallsOrder(field, direction);

            foreach (var ball in sortedBalls)
            {
                var hole = GetHoleForBall(field, direction, ball);
                if (hole != null)
                {
                    field.PutBallInHole(ball, hole);
                }
                else
                {
                    var action = GetTiltAction(direction, field.Size, GetBallsBeforeCount(field, direction, ball));
                    action?.Invoke(ball);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Checks if the tilt was strong enough to pass the treshold values.
        /// </summary>
        /// <param name="direction">Direction of the happening tilt.</param>
        /// <param name="acceleration">Device acceleration of the happening tilt.</param>
        /// <returns>Was the tilt strong enough to pass the needed treshold values.</returns>
        private static bool CheckIsTiltValid(TiltDirection direction, Vector2 acceleration)
        {
            switch (direction)
            {
            case TiltDirection.RIGHT:
                return(acceleration.x >= loadedSettingsData.xTiltPosThreshold);

            case TiltDirection.LEFT:
                return(acceleration.x <= loadedSettingsData.xTiltNegThreshold);

            case TiltDirection.FORWARD:
                return(acceleration.y >= loadedSettingsData.yTiltPosThreshold);

            case TiltDirection.BACKWARD:
                return(acceleration.y <= loadedSettingsData.yTiltNegThreshold);

            case TiltDirection.NONE:
            default:
                return(false);
            }
        }
Beispiel #15
0
 public abstract void TiltMove(string VideoSource, TiltDirection Direction, [System.Xml.Serialization.XmlElementAttribute(DataType = "duration")] string Timeout);