예제 #1
0
    public void InitializeLechonMinigame(GameManager gameManager)
    {
        _gameManager = gameManager;

        clockwiseCombo = new JoystickCombo("Clockwise");
        clockwiseCombo.lowerDeadZoneX = -.2f;
        clockwiseCombo.upperDeadZoneX = .2f;
        clockwiseCombo.lowerDeadZoneY = -.2f;
        clockwiseCombo.upperDeadZoneY = .2f;

        counterClockwiseCombo = new JoystickCombo("CounterClockwise");
        counterClockwiseCombo.lowerDeadZoneX = -.2f;
        counterClockwiseCombo.upperDeadZoneX = .2f;
        counterClockwiseCombo.lowerDeadZoneY = -.2f;
        counterClockwiseCombo.upperDeadZoneY = .2f;

        joystickDirection = JoystickDirection.None;

        checkCombo = false;

        lechonCamera.gameObject.SetActive(false);

        lechonUserInterface = FindObjectOfType <LechonUserInterface>();
        if (lechonUserInterface)
        {
            lechonUserInterface.InitializeLechonUserInterface(gameManager);
        }

        _gameManager.GetPlayer().playerInput.OnLookEvent += OnLookEventCalled;
    }
예제 #2
0
    private void HandleInput()
    {
        var joystickInput = (int)Input.GetAxis("BrightnessP1");
        var aButtonInput  = (int)Input.GetAxis("APlayer1");

        if (aButtonInput == 1)
        {
            GoToScene();
        }

        // Joystick is DOWN
        if (joystickInput < 0 && _joystickDirection != JoystickDirection.Down)
        {
            _joystickDirection = JoystickDirection.Down;
            MoveMenuLocation(-1);
        }

        // Joystick is UP
        if (joystickInput > 0 && _joystickDirection != JoystickDirection.Up)
        {
            _joystickDirection = JoystickDirection.Up;
            MoveMenuLocation(1);
        }

        if (joystickInput == 0)
        {
            _joystickDirection = JoystickDirection.None;
        }
    }
예제 #3
0
 private async Task OnDigitalMoveAsync(JoystickDirection direction)
 {
     if (IsConnected)
     {
         await _bluetoothController.DigitalMoveAsync(direction, Speed);
     }
 }
예제 #4
0
 public void Awake()
 {
     InnerTransform = transform.Find("InnerRegion");
     Debug.Assert(InnerTransform != null, "InnerRegion child not found");
     mPressEvent     = new JoystickEvent();
     mReleaseEvent   = new JoystickEvent();
     mValueChanged   = new JoystickEvent();
     FingerId        = FINGER_NOT_VALID;
     ActiveDirection = JoystickDirection.ALL;
     MaxRadius       = 100;
 }
 public void SetImageBasedOnDirection(JoystickDirection direction)
 {
     if (direction == JoystickDirection.CounterClockwise)
     {
         directionalKey.sprite = counterClockWiseImage;
     }
     else if (direction == JoystickDirection.Clockwise)
     {
         directionalKey.sprite = clockWiseImage;
     }
     directionalKey.gameObject.SetActive(true);
 }
예제 #6
0
        private JoystickDirection GetDirection(Vector2 position)
        {
            JoystickDirection direction = JoystickDirection.Center;

            if (position.Y == -1)
            {
                if (position.X == -1)
                {
                    direction = JoystickDirection.UpLeft;
                }
                else if (position.X == 1)
                {
                    direction = JoystickDirection.UpRight;
                }
                else
                {
                    direction = JoystickDirection.Up;
                }
            }
            else if (position.Y == 1)
            {
                if (position.X == -1)
                {
                    direction = JoystickDirection.DownLeft;
                }
                else if (position.X == 1)
                {
                    direction = JoystickDirection.DownRight;
                }
                else
                {
                    direction = JoystickDirection.Down;
                }
            }
            else
            {
                if (position.X == -1)
                {
                    direction = JoystickDirection.Left;
                }
                else if (position.X == 1)
                {
                    direction = JoystickDirection.Right;
                }
            }

            return(direction);
        }
예제 #7
0
 // Start is called before the first frame update
 void Start()
 {
     _menuLocation      = 0;
     _menuSize          = 3;
     _joystickDirection = JoystickDirection.None;
 }
예제 #8
0
    public void UpdateLechonMinigame()
    {
        if (joystickDirection == JoystickDirection.None)
        {
            int choice = Random.Range(-1, 2);
            if (choice == 1)
            {
                joystickDirection = JoystickDirection.Clockwise;
                lechonUserInterface.SetImageBasedOnDirection(joystickDirection);
            }
            else
            {
                joystickDirection = JoystickDirection.CounterClockwise;
                lechonUserInterface.SetImageBasedOnDirection(joystickDirection);
            }
            checkCombo = true;
        }
        else
        {
            if (checkCombo)
            {
                currentComboTime += Time.deltaTime;
                bool condition = false;

                while (!condition)
                {
                    condition = CheckForCombo(currentComboTime);
                }

                if (condition)
                {
                    if (joystickDirection == JoystickDirection.Clockwise)
                    {
                        if (clockwiseCombo.comboCompleted)
                        {
                            currentCircleCombo++;
                            _gameManager.playerScore++;
                            checkCombo   = false;
                            spinPig      = true;
                            pigDirection = JoystickDirection.Clockwise;
                        }
                    }
                    else if (joystickDirection == JoystickDirection.CounterClockwise)
                    {
                        if (counterClockwiseCombo.comboCompleted)
                        {
                            currentCircleCombo++;
                            _gameManager.playerScore++;
                            checkCombo   = false;
                            spinPig      = true;
                            pigDirection = JoystickDirection.CounterClockwise;
                        }
                    }
                }
                if (currentComboTime >= comboTimeLength)
                {
                    checkCombo       = false;
                    currentComboTime = 0f;
                    Debug.Log("Took too long!");
                }
            }
            else
            {
                clockwiseCombo.index          = 0;
                clockwiseCombo.comboCompleted = false;

                counterClockwiseCombo.index          = 0;
                counterClockwiseCombo.comboCompleted = false;

                currentComboTime = 0f;

                waitForNextChoice += Time.deltaTime;
                if (waitForNextChoice >= nextChoiceTime)
                {
                    joystickDirection = JoystickDirection.None;
                }
            }
        }
        if (spinPig)
        {
            int direction = 1;
            if (pigDirection == JoystickDirection.Clockwise)
            {
                direction = 1;
            }
            else if (pigDirection == JoystickDirection.CounterClockwise)
            {
                direction = -1;
            }

            angle += 20 * Time.deltaTime * rotationSpeed;

            if (angle >= 360)
            {
                spinPig = false;
                angle   = 0;
            }
            pig.RotateAround(pig.transform.position, pig.transform.up * direction, 20 * Time.deltaTime * rotationSpeed);
        }
        if (currentCircleCombo >= maxCircleCombo)
        {
            _gameManager.switchScreen = true;
            _gameManager.objectName   = "Credits";
            CloseMiniGame();
            _gameManager.SwitchScene();
        }
    }
예제 #9
0
    private void DrawIndicators(SKCanvas canvas, float radius)
    {
        var threashHold = radius.Scale(0.05f);

        var previousDirection = Direction;

        canvas.Save();

        var baseRadius = radius.Scale(0.80f);

        var size = radius.Scale(0.08f);

        _indicatorPath = SKPath.ParseSvgPathData($"M-{size} 0L0 {size}L{size} 0L-{size} 0Z");

        _indicatorPaint.ImageFilter = SKImageFilter.CreateDropShadow(0, 1, baseRadius.Scale(0.005f), baseRadius.Scale(0.005f), SKColors.Gray);


        // Top

        canvas.Save();

        var isForward = _position.Y > threashHold;

        _indicatorPaint.Color = isForward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isForward ? Direction & (~JoystickDirection.None) | JoystickDirection.Forward : Direction & (~JoystickDirection.Forward);

        canvas.Translate(0, baseRadius);

        canvas.RotateDegrees(0);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        // Rigth

        canvas.Save();

        var isRigth = _position.X > threashHold;

        _indicatorPaint.Color = isRigth ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isRigth ? Direction & (~JoystickDirection.None) | JoystickDirection.Right : Direction & (~JoystickDirection.Right);

        canvas.Translate(baseRadius, 0);

        canvas.RotateDegrees(-90);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        // Backward

        canvas.Save();

        var isBackward = _position.Y < -threashHold;

        _indicatorPaint.Color = isBackward ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isBackward ? Direction & (~JoystickDirection.None) | JoystickDirection.Backward : Direction & (~JoystickDirection.Backward);

        canvas.Translate(0, -baseRadius);

        canvas.RotateDegrees(180);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();


        // Left

        canvas.Save();

        var isLeft = _position.X < -threashHold;

        _indicatorPaint.Color = isLeft ? IndicatorsColor.ToSKColor() : BackgroundColor.ToEngravedGradientColor(IsEnabled);

        Direction = isLeft ? Direction & (~JoystickDirection.None) | JoystickDirection.Left : Direction & (~JoystickDirection.Left);

        canvas.Translate(-baseRadius, 0);

        canvas.RotateDegrees(90);

        canvas.DrawPath(_indicatorPath, _indicatorPaint);

        canvas.Restore();

        if (!isForward && !isBackward && !isRigth && !isLeft)
        {
            Direction = JoystickDirection.None;
        }

        if (Direction != previousDirection)
        {
            DigitalMoved?.Invoke(this, new EventArgs());
            Execute(Command);
        }

        canvas.Restore();
    }
예제 #10
0
 public JoystickEvent(JoystickAction action, JoystickDirection direction)
 {
     Action    = action;
     Direction = direction;
 }
예제 #11
0
    private Transform ObjectFound(List <Transform> triggerObjects, Transform originCheck, JoystickDirection direction)
    {
        //Transform startingObject = null;
        Transform finalObject = null;

        switch (direction.ToString())
        {
        case "left":
            leftList.Clear();
            foreach (var child in triggerObjects)
            {
                var relativePoint = originCheck.InverseTransformPoint(child.position);
                if (relativePoint.x > 0.0)
                {
                    if (!leftList.Contains(child) || child == originCheck)
                    {
                        leftList.Add(child);
                    }
                }
            }

            leftList = leftList.OrderByDescending(x => x.position.x).ToList();

            finalObject = leftList[0];
            print("Final Object " + finalObject);
            break;

        case "right":
            rightList.Clear();
            foreach (var child in triggerObjects)
            {
                var relativePoint = originCheck.InverseTransformPoint(child.position);
                if (relativePoint.x < 0.0)
                {
                    if (!rightList.Contains(child) || child == originCheck)
                    {
                        rightList.Add(child);
                    }
                }
            }

            rightList   = rightList.OrderByDescending(x => x.position.x).ToList();
            finalObject = rightList[0];
            print("Final Object " + finalObject);
            break;

        case "noDirection":
            finalObject = ClosestObjects(triggerObjects, originCheck);
            break;
        }

        return(finalObject);
    }