예제 #1
0
        /// <summary>
        /// Return the angular difference between this and another angle
        /// </summary>
        /// <param name="value"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public static Double AngularDifference(this Double value, Double other, SpinDirection direction = SpinDirection.None)
        {
            Double diff = 0;

            if (direction == SpinDirection.None)
            {
                diff = Degrees.AngularDifference(value, other);
            }
            else if (direction == SpinDirection.Clockwise)
            {
                diff = other - value;
                if (diff < 0)
                {
                    diff += 360;
                }
            }
            else if (direction == SpinDirection.CounterClockwise)
            {
                diff = value - other;
                if (diff < 0)
                {
                    diff += 360;
                }
            }
            return(diff);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 /// <param name="pUsingMouseWheel">Flag to know if the mouse wheel is used.</param>
 /// <param name="pGoToInfinite">Flag to know if a "go to the infinite" is requested.</param>
 public SpinEventArgs(SpinDirection pDirection, bool pUsingMouseWheel, bool pGoToInfinite)
     : base()
 {
     this.Direction       = pDirection;
     this.UsingMouseWheel = pUsingMouseWheel;
     this.GoToInfinite    = pGoToInfinite;
 }
예제 #3
0
    float RollSpin(SpinDirection direction, float min, float max)
    {
        float degrees = 0;

        if (min > max)
        {
            min = max;
        }

        switch (direction)
        {
        case SpinDirection.COUNTERCLOCKWISE:
            degrees = Random.Range(-max, -min);
            break;

        case SpinDirection.EITHER:
            degrees = Random.Range(-max, max);
            while (Mathf.Abs(degrees) < min)
            {
                degrees = Random.Range(-max, max);
            }
            break;

        case SpinDirection.CLOCKWISE:
            degrees = Random.Range(min, max);
            break;
        }

        return(degrees);
    }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 /// <param name="pUsingMouseWheel">Flag to know if the mouse wheel is used.</param>
 /// <param name="pGoToInfinite">Flag to know if a "go to the infinite" is requested.</param>
 public SpinEventArgs(SpinDirection pDirection, bool pUsingMouseWheel, bool pGoToInfinite)
     : base()
 {
     this.Direction = pDirection;
     this.UsingMouseWheel = pUsingMouseWheel;
     this.GoToInfinite = pGoToInfinite;
 }
예제 #5
0
 /// <summary>
 /// Handle click event of IncreaseButton and DecreaseButton template parts,
 /// translating Click to appropriate Spin event.
 /// </summary>
 /// <param name="sender">Event sender, should be either IncreaseButton or DecreaseButton template part.</param>
 /// <param name="e">Event args.</param>
 private void OnButtonClick(object sender, RoutedEventArgs e)
 {
     if (AllowSpin)
     {
         SpinDirection direction = sender == IncreaseButton ? SpinDirection.Increase : SpinDirection.Decrease;
         OnSpin(new SpinEventArgs(direction));
     }
 }
예제 #6
0
    public float Orbit(Vector3 offsetPosition, Vector3 pivot, SpinDirection direction, float min, float max)
    {
        transform.localPosition = offsetPosition;
        pivotPoint = pivot;

        orbitDegrees = RollSpin(direction, min, max);

        return(orbitDegrees);
    }
        public static void AnimationSpin(this UIView view, SpinDirection type,
                                         double duration = 0.3, Action <bool> onCompletion = null)
        {
            const int iterationCount    = 3;
            var       iterationDuration = duration / iterationCount;
            var       directionSign     = type == SpinDirection.Clockwise ? -1.0f : 1.0f;
            var       angle             = NMath.PI * (2.0f / iterationCount) * directionSign;

            RotateIterationaly(view, iterationCount, angle, iterationDuration, onCompletion);
        }
        /// <summary>
        /// Handle click event of IncreaseButton and DecreaseButton template parts,
        /// translating Click to appropriate Spin event.
        /// </summary>
        /// <param name="sender">Event sender, should be either IncreaseButton or DecreaseButton template part.</param>
        /// <param name="e">Event args.</param>
        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            Debug.Assert(
                sender == IncreaseButton || sender == DecreaseButton,
                "This can't happen: OnButtonClick is called on neither IncreaseButton nor DecreaseButton!");

            SpinDirection direction = sender == IncreaseButton ? SpinDirection.Increase : SpinDirection.Decrease;

            OnSpin(new SpinEventArgs(direction));
        }
예제 #9
0
 public void Rotate(SpinDirection rotationDirection)
 {
     if (IsPlaced)//I.e.if the robot has been placed on a table
     {
         //Futures: If any more orientations are added e.g. North-East,
         //"Enum.GetValues(typeof(Orientation)).Length" will give the number of options.
         int numOrientations = 4;
         _orientation = (Orientation)(((int)_orientation.Value + (int)rotationDirection + numOrientations) % numOrientations);
     }
 }
예제 #10
0
        public void SetDirection(SpinDirection direction)
        {
            Direction = direction;
            switch (direction)
            {
            case SpinDirection.Clockwise:
                DirectionPin.Write(GpioPinValue.High);
                break;

            case SpinDirection.CounterClockwise:
                DirectionPin.Write(GpioPinValue.Low);
                break;
            }
        }
예제 #11
0
    // Start is called before the first frame update
    void Start()
    {
        Sprite sp = GetComponent <Sprite>();

        dir = Random.value > 0.5 ? SpinDirection.right : SpinDirection.left;
        if (dir == SpinDirection.right)
        {
            spinSpeed = -1 * Mathf.Abs(spinSpeed);
        }
        else
        {
            spinSpeed = Mathf.Abs(spinSpeed);
        }
    }
예제 #12
0
        /// <summary>
        /// Spins rover
        /// </summary>
        /// <param name="spinDirection">Spin direction of rover</param>
        public void Spin(SpinDirection spinDirection)
        {
            int angle = (int)CardinalDirection + (int)spinDirection;

            if (angle < 0)
            {
                angle = 360 + angle;
            }
            else if (angle >= 360)
            {
                angle %= 360;
            }

            CardinalDirection = (CardinalDirection)angle;
        }
예제 #13
0
        /// <summary>
        /// Cycles through the available abilities, skipping ones which are PASSIVE
        /// </summary>
        /// <param name="direction"></param>
        private void ChangeAbility(SpinDirection direction)
        {
            SMH.Sound.PlaySound(Sound.SwitchItem);

            //Stop old ability//TODO:
            //smh->player->fireBreathParticle->Stop(false);
            //smh->player->iceBreathParticle->Stop(false);
            SMH.Player.DeShrink();

            int a = 0;
            int b = 0;

            for (int i = 0; i < 3; i++)
            {
                if (direction == SpinDirection.Left)
                {
                    if (_abilitySlots[i].Slot == 0)
                    {
                        a = i;
                    }
                    if (_abilitySlots[i].Slot == 1)
                    {
                        b = i;
                    }
                }
                else if (direction == SpinDirection.Right)
                {
                    if (_abilitySlots[i].Slot == 1)
                    {
                        a = i;
                    }
                    if (_abilitySlots[i].Slot == 2)
                    {
                        b = i;
                    }
                }
            }

            int temp = _abilitySlots[a].Slot;

            _abilitySlots[a].Slot = _abilitySlots[b].Slot;
            _abilitySlots[b].Slot = temp;
        }
예제 #14
0
        protected virtual void Parse(XmlElement element)
        {
            Vector2 position;

            position.x = element.GetFloat("x", 0.0f);
            position.y = element.GetFloat("y", 0.0f);
            Position   = position;

            Vector2 scale = Vector2.one;

            scale.x = element.GetFloat("scale_x", 1.0f);
            scale.y = element.GetFloat("scale_y", 1.0f);
            Scale   = scale;

            Angle_Deg = element.GetFloat("angle", 0.0f);

            int spinVal = element.GetInt("spin", 1);

            Spin = (spinVal == -1) ? SpinDirection.Clockwise : SpinDirection.CounterClockwise;
        }
예제 #15
0
 /// <summary>
 /// Handle click event of buttons template parts, translating Click to appropriate Spin event.
 /// </summary>
 /// <param name="pSender">The event sender.</param>
 /// <param name="pEventArgs">The event arguments.</param>
 private void OnButtonClick(object pSender, RoutedEventArgs pEventArgs)
 {
     if (this.AllowSpin)
     {
         if (pSender == this.IncreaseButton)
         {
             SpinDirection lDirection = SpinDirection.Increase;
             this.NotifySpin(new SpinEventArgs(lDirection));
         }
         else if (pSender == this.DecreaseButton)
         {
             SpinDirection lDirection = SpinDirection.Decrease;
             this.NotifySpin(new SpinEventArgs(lDirection));
         }
         else if (pSender == this.InfiniteButton)
         {
             this.NotifySpin(new SpinEventArgs(true));
         }
     }
 }
예제 #16
0
        public static Task Rotate(this UIView view, float degrees, SpinDirection spinDirection = SpinDirection.Clockwise, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            System.Diagnostics.Debug.WriteLine("degrees: {0}", degrees);
            var rotation = CGAffineTransform.Rotate(view.Transform, (spinDirection == SpinDirection.Clockwise ? 1 : -1) * DegreesToRadians(degrees - .00001f));

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Transform = rotation;
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
        public static ValueAnimator Spin(this View view, SpinDirection spinDirection = SpinDirection.Clockwise, long duration = DefaultAnimationDuration, ITimeInterpolator interpolator = null)
        {
            ObjectAnimator rotation = ObjectAnimator.OfFloat(view, "rotation", 0, 360);

            switch (spinDirection)
            {
            case SpinDirection.Clockwise:
                rotation = ObjectAnimator.OfFloat(view, "rotation", 0, 360);
                break;

            case SpinDirection.CounterClockwise:
                rotation = ObjectAnimator.OfFloat(view, "rotation", 0, -360);
                break;
            }

            rotation.SetDuration(duration);
            rotation.SetInterpolator(interpolator ?? new LinearInterpolator());
            rotation.RepeatCount = ValueAnimator.Infinite;

            rotation.Start();

            return(rotation);
        }
예제 #18
0
 public SpinEventArgs( SpinDirection direction, bool usingMouseWheel )
   : base()
 {
   Direction = direction;
   UsingMouseWheel = usingMouseWheel;
 }
예제 #19
0
        public static async Task Spin(this UIView view, CancellationToken cancellationToken, int numberOfSpins = -1, SpinDirection spinDirection = SpinDirection.Clockwise, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            var splitDuration = duration / 4f;

            if (numberOfSpins > 0)
            {
                for (int i = 0; i < numberOfSpins; i++)
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        await Rotate(view, 90f, spinDirection, splitDuration, animationOptions);
                    }
                }
            }
            else
            {
                do
                {
                    await Rotate(view, 90f, spinDirection, splitDuration, animationOptions);
                } while (!cancellationToken.IsCancellationRequested);
            }

            await ResetAnimation(view, animationOptions : UIViewAnimationOptions.CurveEaseOut);
        }
예제 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 /// <param name="pUsingMouseWheel">Flag to know if the mouse wheel is used.</param>
 public SpinEventArgs(SpinDirection pDirection, bool pUsingMouseWheel)
     : this(pDirection, pUsingMouseWheel, false)
 {
 }
예제 #21
0
        public void Update(float dt)
        {
            CollisionTile collisionAtPlayer = SMH.Player.Tile.Collision;
            SpinDirection dir = SpinDirection.None;

            //Input to change ability
            if (!SMH.WindowManager.IsWindowOpen)
            {
                if (SMH.Input.IsPressed(Input.PreviousAbility))
                {
                    dir = SpinDirection.Left;
                }
                else if (SMH.Input.IsPressed(Input.NextAbility))
                {
                    dir = SpinDirection.Right;
                }
            }

            if (dir != SpinDirection.None)
            {
                if (SelectedAbility == Ability.WATER_BOOTS && SMH.Player.IsSmileyTouchingWater())
                {
                    if (collisionAtPlayer != CollisionTile.DEEP_WATER && collisionAtPlayer != CollisionTile.GREEN_WATER)
                    {
                        //player is on a land tile, but touching water; bump him over and change abilities
                        ChangeAbility(dir);
                        SMH.Player.GraduallyMoveTo(SMH.Player.Tile.X * 64f + 32f, SMH.Player.Tile.Y * 64f + 32f, 500);
                    }
                    else
                    {
                        //player actually on a water tile; cannot take off the sandals; play error message
                        SMH.Sound.PlaySound(Sound.Error);
                    }
                }
                else
                {
                    ChangeAbility(dir);
                }
            }

            float angle, x, y, targetX, targetY;

            for (int i = 0; i < 3; i++)
            {
                //Move towards target slot
                x       = _abilitySlots[i].X;
                y       = _abilitySlots[i].Y;
                targetX = _points[_abilitySlots[i].Slot].X;
                targetY = _points[_abilitySlots[i].Slot].Y;
                angle   = SmileyUtil.GetAngleBetween(x, y, targetX, targetY);
                if (SmileyUtil.Distance(x, y, targetX, targetY) < 600.0 * dt)
                {
                    _abilitySlots[i].X = targetX;
                    _abilitySlots[i].Y = targetY;
                }
                else
                {
                    _abilitySlots[i].X += 600f * (float)Math.Cos(angle) * dt;
                    _abilitySlots[i].Y += 600f * (float)Math.Sin(angle) * dt;
                }

                //Move towards correct size
                if (_abilitySlots[i].Slot == 1 && _abilitySlots[i].Scale < 1f)
                {
                    _abilitySlots[i].Scale += 3f * dt;
                    if (_abilitySlots[i].Scale > 1f)
                    {
                        _abilitySlots[i].Scale = 1f;
                    }
                }
                else if (_abilitySlots[i].Slot != 1 && _abilitySlots[i].Scale > SmallScale)
                {
                    _abilitySlots[i].Scale -= 3f * dt;
                    if (_abilitySlots[i].Scale < SmallScale)
                    {
                        _abilitySlots[i].Scale = SmallScale;
                    }
                }
            }
        }
예제 #22
0
        protected virtual void Parse(XmlElement element)
        {
            Vector2 position;
            position.x = element.GetFloat("x", 0.0f);
            position.y = element.GetFloat("y", 0.0f);
            Position = position;

            Vector2 scale = Vector2.one;
            scale.x = element.GetFloat("scale_x", 1.0f);
            scale.y = element.GetFloat("scale_y", 1.0f);
            Scale = scale;

            Angle_Deg = element.GetFloat("angle", 0.0f);

            int spinVal = element.GetInt("spin", 1);
            Spin = (spinVal == -1) ? SpinDirection.Clockwise : SpinDirection.CounterClockwise;
        }
 private void GetNextSpin(SpinDirection direction, ref int index)
 {
     if (direction == SpinDirection.Increase)
     {
         if (index < (numberOfPrices - 1))
         {
             index++;
         }
     }
     else
     {
         if (index > 0)
         {
             index--;
         }
     }
     RaisePropertyChanged(() => BackOdds);
     RaisePropertyChanged(() => LayOdds);
 }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 public SpinEventArgs(SpinDirection pDirection)
     : this(pDirection, false, false)
 {
 }
예제 #25
0
 public SpinEventArgs(RoutedEvent routedEvent, SpinDirection direction, bool usingMouseWheel)
     : base(routedEvent)
 {
     Direction       = direction;
     UsingMouseWheel = usingMouseWheel;
 }
예제 #26
0
 public SpinEventArgs(RoutedEvent routedEvent, SpinDirection direction)
     : base(routedEvent)
 {
     Direction = direction;
 }
예제 #27
0
    public float Spin(SpinDirection direction, float min, float max)
    {
        spinDegrees = RollSpin(direction, min, max);

        return(spinDegrees);
    }
예제 #28
0
        protected virtual void Parse(XmlElement element)
        {
            Vector2 position;
            position.x = element.GetFloat("x", 0.0f);
            position.y = element.GetFloat("y", 0.0f);
            Position = position;

            Vector2 scale = Vector2.one;
            scale.x = element.GetFloat("scale_x", 1.0f);
            scale.y = element.GetFloat("scale_y", 1.0f);
            Scale = scale;

            Angle_Deg = element.GetFloat("angle", 0.0f);

            Spin = (SpinDirection)element.GetInt("spin", 1);
        }
예제 #29
0
 public SpinEventArgs(SpinDirection direction, bool usingMouseWheel)
     : base()
 {
     Direction       = direction;
     UsingMouseWheel = usingMouseWheel;
 }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 public SpinEventArgs(SpinDirection pDirection)
     : this(pDirection, false, false)
 {
 }
예제 #31
0
 /// <summary>
 /// Initializes a new instance of the SpinEventArgs class.
 /// </summary>
 /// <param name="direction">Spin direction.</param>
 public SpinEventArgs( SpinDirection direction )
   : base()
 {
   Direction = direction;
 }
예제 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpinEventArgs"/> class.
 /// </summary>
 /// <param name="pDirection">The spin direction.</param>
 /// <param name="pUsingMouseWheel">Flag to know if the mouse wheel is used.</param>
 public SpinEventArgs(SpinDirection pDirection, bool pUsingMouseWheel)
     : this(pDirection, pUsingMouseWheel, false)
 {
 }
예제 #33
0
 /// <summary>
 /// Initializes a new instance of the SpinEventArgs class.
 /// </summary>
 /// <param name="direction">Spin direction.</param>
 public SpinEventArgs(SpinDirection direction)
     : base()
 {
     Direction = direction;
 }
 /// <summary>
 /// Convert spin direction to symbol
 /// </summary>
 /// <param name="spinDirection">Spin Direction</param>
 /// <returns>Symbol</returns>
 public static char ToSymbol(this SpinDirection spinDirection)
 {
     return(spinDirection.ToString()[0]);
 }