Exemple #1
0
        /// <summary>
        /// Sets new bounds for the joystick oval
        /// </summary>
        /// <param name="xPosition">X-Position of the touch</param>
        /// <param name="yPosition">Y-Position of the touch</param>
        private void UpdateOvals(float xPosition, float yPosition)
        {
            // Check if touch is in left or right half of the screen
            if (xPosition <= ScreenWidth / 2)
            {
                // Handle touch in the left half
                m_LeftJS.SetPosition(xPosition, yPosition);
                // Check if touch was inside the displacement radius
                if ((m_LeftJS.Abs) <= Joystick.DisplacementRadius)
                {
                    // Draw left joystick with original coordinates
                    SetBoundsForLeftStick(
                        (int)xPosition - (int)Joystick.StickRadius,
                        (int)yPosition - (int)Joystick.StickRadius,
                        (int)xPosition + (int)Joystick.StickRadius,
                        (int)yPosition + (int)Joystick.StickRadius);
                }
                else
                {
                    // Draw left joystick with maximum coordinates
                    SetBoundsForLeftStick(
                        (int)(Joystick.DisplacementRadius * Math.Cos(m_LeftJS.Angle * Math.PI / 180)) - (int)Joystick.StickRadius + (int)m_LeftJS.CenterX,
                        (int)(Joystick.DisplacementRadius * Math.Sin(m_LeftJS.Angle * Math.PI / 180)) - (int)Joystick.StickRadius + (int)m_LeftJS.CenterY,
                        (int)(Joystick.DisplacementRadius * Math.Cos(m_LeftJS.Angle * Math.PI / 180)) + (int)Joystick.StickRadius + (int)m_LeftJS.CenterX,
                        (int)(Joystick.DisplacementRadius * Math.Sin(m_LeftJS.Angle * Math.PI / 180)) + (int)Joystick.StickRadius + (int)m_LeftJS.CenterY);

                    // OPTION: Set radius as position
                    //m_LeftJS.SetPosition((int)(m_LeftJS.m_DisplacementRadius * Math.Cos(m_LeftJS.GetAngle() * Math.PI / 180)) + (int)m_LeftJS.CENTER_X,
                    //    (int)(m_LeftJS.m_DisplacementRadius * Math.Sin(m_LeftJS.GetAngle() * Math.PI / 180)) + (int)m_LeftJS.CENTER_Y);
                }
            }
            else
            {
                // Handle touch in the right half
                m_RightJS.SetPosition(xPosition, yPosition);
                // Check if touch was inside the displacement radius
                if ((m_RightJS.Abs) <= Joystick.DisplacementRadius)
                {
                    // Draw right joystick with original coordinates
                    SetBoundsForRightStick(
                        (int)xPosition - (int)Joystick.StickRadius,
                        (int)yPosition - (int)Joystick.StickRadius,
                        (int)xPosition + (int)Joystick.StickRadius,
                        (int)yPosition + (int)Joystick.StickRadius);
                }
                else
                {
                    // Draw left joystick with maximum coordinates
                    SetBoundsForRightStick(
                        (int)(Joystick.DisplacementRadius * Math.Cos(m_RightJS.Angle * Math.PI / 180)) - (int)Joystick.StickRadius + (int)m_RightJS.CenterX,
                        (int)(Joystick.DisplacementRadius * Math.Sin(m_RightJS.Angle * Math.PI / 180)) - (int)Joystick.StickRadius + (int)m_RightJS.CenterY,
                        (int)(Joystick.DisplacementRadius * Math.Cos(m_RightJS.Angle * Math.PI / 180)) + (int)Joystick.StickRadius + (int)m_RightJS.CenterX,
                        (int)(Joystick.DisplacementRadius * Math.Sin(m_RightJS.Angle * Math.PI / 180)) + (int)Joystick.StickRadius + (int)m_RightJS.CenterY);

                    // OPTION: Set radius as position
                    //m_RightJS.SetPosition((int)(m_RightJS.m_DisplacementRadius * Math.Cos(m_RightJS.GetAngle() * Math.PI / 180)) + (int)m_RightJS.CENTER_X,
                    //    (int)(m_RightJS.m_DisplacementRadius * Math.Sin(m_RightJS.GetAngle() * Math.PI / 180)) + (int)m_RightJS.CENTER_Y);
                }
            }
        }
 /// <summary>
 /// Sets new bounds for the joystick oval
 /// </summary>
 /// <param name="xPosition">X-Position of the touch</param>
 /// <param name="yPosition">Y-Position of the touch</param>
 private void UpdateOvals(float xPosition, float yPosition)
 {
     // Check if touch is in left or right of the screen
     if (xPosition <= SCREEN_WIDTH / 2)
     {
         // Handle touch in the left half
         m_LeftJS.SetPosition(xPosition, yPosition);
         m_LeftJS.GetPower();
         // Check if touch was inside the displacement radius
         if ((m_LeftJS.GetAbs()) <= m_LeftJS.m_DisplacementRadius) // if((abs + m_LeftJS.m_StickRadius...
         {
             // Draw left joystick with original coordinates
             SetBoundsForLeftStick(
                 (int)xPosition - (int)m_LeftJS.m_StickRadius,
                 (int)yPosition - (int)m_LeftJS.m_StickRadius,
                 (int)xPosition + (int)m_LeftJS.m_StickRadius,
                 (int)yPosition + (int)m_LeftJS.m_StickRadius);
         }
         else
         {
             // Draw left joystick with maximum coordinates
             SetBoundsForLeftStick(
                 (int)(m_LeftJS.m_DisplacementRadius * Math.Cos(m_LeftJS.GetAngle() * Math.PI / 180)) - (int)m_LeftJS.m_StickRadius + (int)m_LeftJS.CENTER_X,
                 (int)(m_LeftJS.m_DisplacementRadius * Math.Sin(m_LeftJS.GetAngle() * Math.PI / 180)) - (int)m_LeftJS.m_StickRadius + (int)m_LeftJS.CENTER_Y,
                 (int)(m_LeftJS.m_DisplacementRadius * Math.Cos(m_LeftJS.GetAngle() * Math.PI / 180)) + (int)m_LeftJS.m_StickRadius + (int)m_LeftJS.CENTER_X,
                 (int)(m_LeftJS.m_DisplacementRadius * Math.Sin(m_LeftJS.GetAngle() * Math.PI / 180)) + (int)m_LeftJS.m_StickRadius + (int)m_LeftJS.CENTER_Y);
         }
     }
     else
     {
         // Handle touch in the right half
         m_RightJS.SetPosition(xPosition, yPosition);
         // Check if touch was inside the displacement radius
         if ((m_RightJS.GetAbs()) <= m_RightJS.m_DisplacementRadius)
         {
             // Draw right joystick with original coordinates
             SetBoundsForRightStick(
                 (int)xPosition - (int)m_RightJS.m_StickRadius,
                 (int)yPosition - (int)m_RightJS.m_StickRadius,
                 (int)xPosition + (int)m_RightJS.m_StickRadius,
                 (int)yPosition + (int)m_RightJS.m_StickRadius);
         }
         else
         {
             // Draw left joystick with maximum coordinates
             SetBoundsForRightStick(
                 (int)(m_RightJS.m_DisplacementRadius * Math.Cos(m_RightJS.GetAngle() * Math.PI / 180)) - (int)m_RightJS.m_StickRadius + (int)m_RightJS.CENTER_X,
                 (int)(m_RightJS.m_DisplacementRadius * Math.Sin(m_RightJS.GetAngle() * Math.PI / 180)) - (int)m_RightJS.m_StickRadius + (int)m_RightJS.CENTER_Y,
                 (int)(m_RightJS.m_DisplacementRadius * Math.Cos(m_RightJS.GetAngle() * Math.PI / 180)) + (int)m_RightJS.m_StickRadius + (int)m_RightJS.CENTER_X,
                 (int)(m_RightJS.m_DisplacementRadius * Math.Sin(m_RightJS.GetAngle() * Math.PI / 180)) + (int)m_RightJS.m_StickRadius + (int)m_RightJS.CENTER_Y);
         }
     }
 }