예제 #1
0
    private void SwitchItem(bool reverse = false)
    {
        if (!reverse)
        {
            SelectedItem++;
            if (SelectedItem > 2)
            {
                SelectedItem = 0;
            }
        }
        else
        {
            SelectedItem--;
            if (SelectedItem < 0)
            {
                SelectedItem = 2;
            }
        }

        JumpItem.CleanUp();
        switch (SelectedItem)
        {
        case (0): JumpItem = new Glider(this);
            JumpItem.Activate();
            break;

        case (1):
            JumpItem = new Parachute(this);
            JumpItem.Activate();
            break;

        case (2): JumpItem = new BouncyBall(this); break;
        }
    }
예제 #2
0
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }

        bool moveForward = false;
        bool moveLeft    = false;
        bool moveRight   = false;
        bool moveBack    = false;

        MoveScale = 1.0f;

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }
        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight = true;
        }
        if (Input.GetKeyDown(KeyCode.R) || Input.GetButtonDown("ButtonStart"))
        {
            Reset();
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            SwitchItem();
        }


        float lt = Input.GetAxis("TriggersL_1");
        float rt = Input.GetAxis("TriggersR_1");


        if (!LeftTriggerDown && lt == 1)
        {
            SwitchItem(true);
            LeftTriggerDown = true;
        }
        else if (LeftTriggerDown && lt == -1)
        {
            LeftTriggerDown = false;
        }

        if (!RightTriggerDown && rt == 1)
        {
            SwitchItem(false);
            RightTriggerDown = true;
        }
        else if (RightTriggerDown && rt == -1)
        {
            RightTriggerDown = false;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        //if (!Controller.isGrounded)
        //MoveScale = 0.0f;

        if (Input.GetButtonDown("ButtonA") || Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }


        //if(JumpItem != null) {
        if ((Input.GetKeyDown(KeyCode.F) || Input.GetButtonDown("ButtonB")) && JumpItem.isUsable)
        {
            JumpItem.Activate();
        }
        JumpItem.Update();
        //}

        MoveScale *= DeltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        // Rotate

        // compute for key rotation
        float rotateInfluence = DeltaTime * RotationAmount * RotationScaleMultiplier;

        //reduce by half to avoid getting ill
        if (Input.GetKey(KeyCode.Q))
        {
            YRotation -= rotateInfluence * 0.5f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            YRotation += rotateInfluence * 0.5f;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate
        float deltaRotation = 0.0f;

        if (AllowMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("R_XAxis_0") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        float leftAxisY = Input.GetAxis("L_YAxis_1");

        float leftAxisX = Input.GetAxis("L_XAxis_1");

        float axisStrength = Mathf.Abs(leftAxisY) > Mathf.Abs(leftAxisX) ? Mathf.Abs(leftAxisY) : Mathf.Abs(leftAxisX);

        // Run!
        moveInfluence *= 1.0f + axisStrength;

        // Move
        if (DirXform != null)
        {
            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.RightXAxis);

        // Rotate
        YRotation += rightAxisX * rotateInfluence;

        if (transform.position.y < 0)
        {
            Stop();
            Die();
        }


        // Update cameras direction and rotation
        SetCameras();
    }