Ejemplo n.º 1
0
    /////////////////////////////////////////////////////////////////
    // Takes player input
    /////////////////////////////////////////////////////////////////
    public void PlayerInput()
    {
        // EXIT
        if (Input.GetButtonDown("Exit"))
        {
            Application.Quit();
        }

        // CAMERA

        if (Input.GetAxis("Mouse X") != 0.0f ||
            Input.GetAxis("Mouse Y") != 0.0f)
        {
            MoveCamera(Input.GetAxis("Mouse X"),
                       Input.GetAxis("Mouse Y"));
        }

        // MOVEMENT

        switch (playerScript.GetMovementState())
        {
        case MovementState.STANDING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player crouchs
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.CROUCHING);
            }

            // If player inputs movement
            else if (Input.GetAxis("Horizontal") != 0.0f ||
                     Input.GetAxis("Vertical") != 0.0f)
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }
            break;

        case MovementState.CROUCHING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player stands up
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // If player inputs movement
            else if (Input.GetAxis("Horizontal") != 0.0f ||
                     Input.GetAxis("Vertical") != 0.0f)
            {
                playerScript.SetMovementState(MovementState.SNEAKING);
            }
            break;

        case MovementState.SNEAKING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player stands up
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.CROUCHING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.WALKING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player crouchs
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.SNEAKING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }

            // Player runs
            else if (Input.GetButton("Sprint") ||
                     Input.GetAxis("Sprint") == 1)
            {
                playerScript.SetMovementState(MovementState.RUNNING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.RUNNING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player slides
            else if (Input.GetButton("Crouch") &&
                     playerScript.CanSlide())
            {
                playerScript.SetMovementState(MovementState.SLIDING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }

            // Player runs
            else if (!Input.GetButton("Sprint") &&
                     Input.GetAxis("Sprint") != 1)
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.JUMPING:
        case MovementState.FALLING:

            // Player lands
            if (playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // If player inputs movement
            if (Input.GetAxis("Horizontal") != 0.0f ||
                Input.GetAxis("Vertical") != 0.0f)
            {
                // Pass input axis into move function
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.CLIMBING:
            if (playerScript.GetStatePhase() == StatePhase.END)
            {
                // Player on ground
                if (playerScript.CanJump())
                {
                    playerScript.SetMovementState(MovementState.STANDING);
                }

                // Player jumps
                else if (Input.GetButtonDown("Jump"))
                {
                    playerScript.Jump();
                }

                // Player moves
                else
                {
                    playerScript.Move(Input.GetAxis("Horizontal"),
                                      Input.GetAxis("Vertical"));
                }
            }
            break;

        default:
            break;
        }

        // FOR TESTING PURPOSES ONLY!

        if (Input.GetKeyDown("1"))
        {
            playerScript.SetMovementState(MovementState.VAULTING);
        }

        if (Input.GetKeyDown("2"))
        {
            playerScript.SetMovementState(MovementState.SLIDING);
        }

        if (Input.GetKeyDown("3"))
        {
            playerScript.SetMovementState(MovementState.MANTLING);
        }

        if (Input.GetKeyDown("4"))
        {
            playerScript.SetMovementState(MovementState.CLIMBING);
        }
    }