Example #1
0
        /// <summary>
        /// Allow the player to move around in the scene
        /// </summary>
        void PlayerMovement()
        {
            switch (ControllerType)
            {
            case SupportedControllers.ArcadeBoard:

                if (ArcadeControls.JoystickLeft(Player))
                {
                    RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.left);
                }

                if (ArcadeControls.JoystickRight(Player))
                {
                    RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.right);
                }

                if (ArcadeControls.JoystickUp(Player))
                {
                    RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                    //UpdateGunshipDirection(Vector2.up);
                }

                if (ArcadeControls.JoystickDown(Player))
                {
                    RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                    //UpdateGunshipDirection(Vector2.down);
                }

                if (ArcadeControls.JoystickNorthEast(Player))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                }

                if (ArcadeControls.JoystickNorthWest(Player))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                }

                if (ArcadeControls.JoystickSouthEast(Player))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                }

                if (ArcadeControls.JoystickSouthWest(Player))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                }

                if (ArcadeControls.JoystickNone(Player))
                {
                    RB.velocity = Vector2.zero;
                }

                break;

            case SupportedControllers.GamePadBoth:

                if (ControllerControls.ControllerLeft(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.left);
                }

                if (ControllerControls.ControllerRight(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.right);
                }

                if (ControllerControls.ControllerUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                    //UpdateGunshipDirection(Vector2.up);
                }

                if (ControllerControls.ControllerDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                    //UpdateGunshipDirection(Vector2.down);
                }

                if (ControllerControls.ControllerLeftUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                }

                if (ControllerControls.ControllerRightUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                }

                if (ControllerControls.ControllerLeftDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                }

                if (ControllerControls.ControllerRightDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                }

                if (ControllerControls.ControllerNone(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.zero;
                }

                break;

            case SupportedControllers.KeyboardBoth:

                if (KeyboardControls.KeyboardLeft(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.left);
                }
                if (KeyboardControls.KeyboardRight(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.right);
                }
                if (KeyboardControls.KeyboardUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                    // UpdateGunshipDirection(Vector2.up);
                }
                if (KeyboardControls.KeyboardDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                    //UpdateGunshipDirection(Vector2.down);
                }
                if (KeyboardControls.KeyboardLeftUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                }
                if (KeyboardControls.KeyboardRightUp(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                }
                if (KeyboardControls.KeyboardLeftDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                }
                if (KeyboardControls.KeyboardRightDown(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                    UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                }
                if (KeyboardControls.KeyboardNone(ConvertToPlayers()))
                {
                    RB.velocity = Vector2.zero;
                }

                break;

            case SupportedControllers.KeyboardP1ControllerP2:

                if (ConvertToPlayers() == Players.P1)
                {
                    if (KeyboardControls.KeyboardLeft(Players.P1))
                    {
                        RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.left);
                    }
                    if (KeyboardControls.KeyboardRight(Players.P1))
                    {
                        RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.right);
                    }
                    if (KeyboardControls.KeyboardUp(Players.P1))
                    {
                        RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                        //UpdateGunshipDirection(Vector2.up);
                    }
                    if (KeyboardControls.KeyboardDown(Players.P1))
                    {
                        RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                        //UpdateGunshipDirection(Vector2.down);
                    }
                    if (KeyboardControls.KeyboardLeftUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                    }
                    if (KeyboardControls.KeyboardRightUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                    }
                    if (KeyboardControls.KeyboardLeftDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                    }
                    if (KeyboardControls.KeyboardRightDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                    }
                    if (KeyboardControls.KeyboardNone(Players.P1))
                    {
                        RB.velocity = Vector2.zero;
                    }
                }
                else
                {
                    if (ControllerControls.ControllerLeft(Players.P1))
                    {
                        RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.left);
                    }

                    if (ControllerControls.ControllerRight(Players.P1))
                    {
                        RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.right);
                    }

                    if (ControllerControls.ControllerUp(Players.P1))
                    {
                        RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                        //UpdateGunshipDirection(Vector2.up);
                    }

                    if (ControllerControls.ControllerDown(Players.P1))
                    {
                        RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                        //UpdateGunshipDirection(Vector2.down);
                    }

                    if (ControllerControls.ControllerLeftUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                    }

                    if (ControllerControls.ControllerRightUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                    }

                    if (ControllerControls.ControllerLeftDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                    }

                    if (ControllerControls.ControllerRightDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                    }

                    if (ControllerControls.ControllerNone(Players.P1))
                    {
                        RB.velocity = Vector2.zero;
                    }
                }

                break;

            case SupportedControllers.KeyboardP2ControllerP1:

                if (ConvertToPlayers() == Players.P2)
                {
                    if (KeyboardControls.KeyboardLeft(Players.P1))
                    {
                        RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.left);
                    }
                    if (KeyboardControls.KeyboardRight(Players.P1))
                    {
                        RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.right);
                    }
                    if (KeyboardControls.KeyboardUp(Players.P1))
                    {
                        RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.up);
                    }
                    if (KeyboardControls.KeyboardDown(Players.P1))
                    {
                        RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.down);
                    }
                    if (KeyboardControls.KeyboardLeftUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                    }
                    if (KeyboardControls.KeyboardRightUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                    }
                    if (KeyboardControls.KeyboardLeftDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                    }
                    if (KeyboardControls.KeyboardRightDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                    }
                    if (KeyboardControls.KeyboardNone(Players.P1))
                    {
                        RB.velocity = Vector2.zero;
                    }
                }
                else
                {
                    if (ControllerControls.ControllerLeft(Players.P1))
                    {
                        RB.velocity = Vector2.left * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.left);
                    }

                    if (ControllerControls.ControllerRight(Players.P1))
                    {
                        RB.velocity = Vector2.right * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.right);
                    }

                    if (ControllerControls.ControllerUp(Players.P1))
                    {
                        RB.velocity = Vector2.up * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.up);
                    }

                    if (ControllerControls.ControllerDown(Players.P1))
                    {
                        RB.velocity = Vector2.down * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.down);
                    }

                    if (ControllerControls.ControllerLeftUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.right, 1f));
                    }

                    if (ControllerControls.ControllerRightUp(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.up + Vector2.left, 1f));
                    }

                    if (ControllerControls.ControllerLeftDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.right, 1f));
                    }

                    if (ControllerControls.ControllerRightDown(Players.P1))
                    {
                        RB.velocity = Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f) * MoveSpd * Time.deltaTime;
                        UpdateGunshipDirection(Vector2.ClampMagnitude(Vector2.down + Vector2.left, 1f));
                    }

                    if (ControllerControls.ControllerNone(Players.P1))
                    {
                        RB.velocity = Vector2.zero;
                    }
                }

                break;

            default:
                break;
            }
        }
Example #2
0
        private void FixedUpdate()
        {
            // Switches the flippers between left and right
            switch (ThisFlipper)
            {
            case FlipperSides.Left:

                switch (ControllerType)
                {
                case SupportedControllers.ArcadeBoard:

                    if (ArcadeControls.JoystickLeft(Input))
                    {
                        FlipLeftFlipper();
                    }
                    else if (ArcadeControls.JoystickNone(Input))
                    {
                        ResetLeftFlipper();
                    }

                    break;

                case SupportedControllers.GamePadBoth:

                    if (ControllerControls.ControllerLeft(ConvertToPlayers()))
                    {
                        FlipLeftFlipper();
                    }
                    else if (ControllerControls.ControllerNone(ConvertToPlayers()))
                    {
                        ResetLeftFlipper();
                    }

                    break;

                case SupportedControllers.KeyboardBoth:

                    if (KeyboardControls.KeyboardLeft(ConvertToPlayers()))
                    {
                        FlipLeftFlipper();
                    }
                    else if (KeyboardControls.KeyboardNone(ConvertToPlayers()))
                    {
                        ResetLeftFlipper();
                    }

                    break;

                case SupportedControllers.KeyboardP1ControllerP2:

                    if (ConvertToPlayers() == Players.P1)
                    {
                        if (KeyboardControls.KeyboardLeft(Players.P1))
                        {
                            FlipLeftFlipper();
                        }
                        else if (KeyboardControls.KeyboardNone(Players.P1))
                        {
                            ResetLeftFlipper();
                        }
                    }
                    else
                    {
                        if (ControllerControls.ControllerLeft(Players.P1))
                        {
                            FlipLeftFlipper();
                        }
                        else if (ControllerControls.ControllerNone(Players.P1))
                        {
                            ResetLeftFlipper();
                        }
                    }

                    break;

                case SupportedControllers.KeyboardP2ControllerP1:

                    if (ConvertToPlayers() == Players.P2)
                    {
                        if (KeyboardControls.KeyboardLeft(Players.P1))
                        {
                            FlipLeftFlipper();
                        }
                        else if (KeyboardControls.KeyboardNone(Players.P1))
                        {
                            ResetLeftFlipper();
                        }
                    }
                    else
                    {
                        if (ControllerControls.ControllerLeft(Players.P1))
                        {
                            FlipLeftFlipper();
                        }
                        else if (ControllerControls.ControllerNone(Players.P1))
                        {
                            ResetLeftFlipper();
                        }
                    }

                    break;

                default:
                    break;
                }


                break;

            case FlipperSides.Right:

                switch (ControllerType)
                {
                case SupportedControllers.ArcadeBoard:

                    if (ArcadeControls.JoystickRight(Input))
                    {
                        FlipRightFlipper();
                    }
                    else if (ArcadeControls.JoystickNone(Input))
                    {
                        ResetRightFlipper();
                    }

                    break;

                case SupportedControllers.GamePadBoth:

                    if (ControllerControls.ControllerRight(ConvertToPlayers()))
                    {
                        FlipRightFlipper();
                    }
                    else if (ControllerControls.ControllerNone(ConvertToPlayers()))
                    {
                        ResetRightFlipper();
                    }

                    break;

                case SupportedControllers.KeyboardBoth:

                    if (KeyboardControls.KeyboardRight(ConvertToPlayers()))
                    {
                        FlipRightFlipper();
                    }
                    else if (KeyboardControls.KeyboardNone(ConvertToPlayers()))
                    {
                        ResetRightFlipper();
                    }

                    break;

                case SupportedControllers.KeyboardP1ControllerP2:

                    if (ConvertToPlayers() == Players.P1)
                    {
                        if (KeyboardControls.KeyboardRight(Players.P1))
                        {
                            FlipRightFlipper();
                        }
                        else if (KeyboardControls.KeyboardNone(Players.P1))
                        {
                            ResetRightFlipper();
                        }
                    }
                    else
                    {
                        if (ControllerControls.ControllerRight(Players.P1))
                        {
                            FlipRightFlipper();
                        }
                        else if (ControllerControls.ControllerNone(Players.P1))
                        {
                            ResetRightFlipper();
                        }
                    }

                    break;

                case SupportedControllers.KeyboardP2ControllerP1:

                    if (ConvertToPlayers() == Players.P2)
                    {
                        if (KeyboardControls.KeyboardRight(Players.P1))
                        {
                            FlipRightFlipper();
                        }
                        else if (KeyboardControls.KeyboardNone(Players.P1))
                        {
                            ResetRightFlipper();
                        }
                    }
                    else
                    {
                        if (ControllerControls.ControllerRight(Players.P1))
                        {
                            FlipRightFlipper();
                        }
                        else if (ControllerControls.ControllerNone(Players.P1))
                        {
                            ResetRightFlipper();
                        }
                    }

                    break;

                default:
                    break;
                }


                break;

            default:
                break;
            }
        }