Beispiel #1
0
    void Update()
    {
        // Store the input axes.
        h = XCI.GetAxis(XboxAxis.LeftStickX, joystick);
        v = XCI.GetAxis(XboxAxis.LeftStickY, joystick);

        // Set the input axes on the Animator Controller.
        anim.SetFloat(hFloat, h, 0.1f, Time.deltaTime);
        anim.SetFloat(vFloat, v, 0.1f, Time.deltaTime);

        // Toggle sprint by input.
        sprint = XCI.GetDPad(XboxDPad.Up, joystick);

        // Set the correct camera FOV for sprint mode.
        if (IsSprinting())
        {
            changedFOV = true;
            camScript.SetFOV(sprintFOV);
        }
        else if (changedFOV)
        {
            camScript.ResetFOV();
            changedFOV = false;
        }
        // Set the grounded test on the Animator Controller.
        anim.SetBool(groundedBool, IsGrounded());

        if (IsGrounded())
        {
            GetRigidBody.drag = 0;
        }
    }
Beispiel #2
0
        /// <summary>
        /// returns a specified axis
        /// </summary>
        /// <param name="axis">One of the analogue sticks, or the dpad</param>
        /// <param name="controlIndex">The controller number</param>
        /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param>
        /// <returns></returns>
        public static Vector2 GetAxis(Axis axis, Index controlIndex, bool raw = false)
        {
            XboxAxisz xName  = XboxAxisz.LeftStickX;
            XboxAxisz yName  = XboxAxisz.LeftStickY;
            Vector2   axisXY = Vector3.zero;

            switch (axis)
            {
            case Axis.Dpad:
                axisXY.x  = XCI.GetDPad(XboxDPad.Up)? 1.0f:0.0f;
                axisXY.x -= XCI.GetDPad(XboxDPad.Down) ? 1.0f : 0.0f;
                axisXY.y  = XCI.GetDPad(XboxDPad.Right) ? 1.0f : 0.0f;
                axisXY.y -= XCI.GetDPad(XboxDPad.Left) ? 1.0f : 0.0f;
                return(axisXY);

            //break;
            case Axis.LeftStick:
                xName = XboxAxisz.LeftStickX;
                // "XboxAxisXJoy" + (int)controlIndex;
                yName = XboxAxisz.LeftStickY;
                //"XboxAxisYJoy" + (int)controlIndex;
                break;

            case Axis.RightStick:
                xName = XboxAxisz.RightStickX;
                //"XboxAxis4Joy" + (int)controlIndex;
                yName = XboxAxisz.RightStickY;
                //"XboxAxis5Joy" + (int)controlIndex;
                break;
            }
            ;

            try
            {
                if (raw == false)
                {
                    axisXY.x = XCI.GetAxis((XboxAxis)xName, (XboxController)controlIndex);
                    axisXY.y = XCI.GetAxis((XboxAxis)yName, (XboxController)controlIndex);
                }
                else
                {
                    axisXY.x = XCI.GetAxisRaw((XboxAxis)xName, (XboxController)controlIndex);
                    axisXY.y = XCI.GetAxisRaw((XboxAxis)yName, (XboxController)controlIndex);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
                Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
            }
            return(axisXY);
        }
Beispiel #3
0
    public float Value(int xboxController)
    {
        float v = 0;

        switch (Type)
        {
        case ControlKeyType.PC:
            if (Input.GetKey(ControlHelper.ReturnKeyCode(keys[0])))
            {
                v--;
            }
            if (Input.GetKey(ControlHelper.ReturnKeyCode(keys[1])))
            {
                v++;
            }
            break;

        case ControlKeyType.Xbox:
            if (xboxAxisType == XboxAxisType.axis)
            {
                v = XCI.GetAxis(ControlHelper.ReturnXboxAxis(keys[0]), xboxController);
            }
            else
            {
                if (XCI.GetDPad(ControlHelper.ReturnXboxDPad(keys[0]), xboxController))
                {
                    v--;
                }
                if (XCI.GetDPad(ControlHelper.ReturnXboxDPad(keys[1]), xboxController))
                {
                    v++;
                }
            }

            break;

        default:
            return(0);
        }
        return(v);
    }
Beispiel #4
0
        public override float GetAxisCurrentState(float mouseSensibility, float joystickSensibility, bool invertVerticalAxis, bool isVertical)
        {
            // As XboxJoystickButtons is an exact copy of XboxButton
            // in this implementation, I can just cast the enum.
            var positive = XCI.GetDPad((XboxDPad)this.positiveButton);
            var negative = XCI.GetDPad((XboxDPad)this.negativeButton);
            var value    = 0;

            if (positive && !negative)
            {
                value = 1;
            }
            else if (negative && !positive)
            {
                value = -1;
            }

            if (invertVerticalAxis)
            {
                value *= -1;
            }

            return(value);
        }
    // Update
    void Update()
    {
        GameObject bulletReference = null;

        // Jump (Left Stick)
        if (XCI.GetButtonDown(XboxButton.LeftStick, playerNumber) && canJump)
        {
            canJump = false;
            GetComponent <Rigidbody>().AddRelativeForce(0.0f, jumpImpulse, 0.0f, ForceMode.Impulse);
        }

        // Slam (Right Stick)
        if (XCI.GetButtonDown(XboxButton.RightStick, playerNumber) && !canJump)
        {
            GetComponent <Rigidbody>().AddRelativeForce(0.0f, (-jumpImpulse * 1.5f), 0.0f, ForceMode.Impulse);
        }


        // Shoot colored laser (A,B,X,Y)
        if (bulletTimer > 0.0f)
        {
            bulletTimer -= Time.deltaTime;
        }

        if (bulletTimer <= 0.0f)
        {
            if (XCI.GetButton(XboxButton.A, playerNumber))
            {
                Instantiate(laserAPrefab, transform.position, laserAPrefab.transform.rotation);
                bulletTimer = MAX_BUL_TME;
            }
            if (XCI.GetButton(XboxButton.B, playerNumber))
            {
                Instantiate(laserBPrefab, transform.position, laserBPrefab.transform.rotation);
                bulletTimer = MAX_BUL_TME;
            }
            if (XCI.GetButton(XboxButton.X, playerNumber))
            {
                Instantiate(laserXPrefab, transform.position, laserXPrefab.transform.rotation);
                bulletTimer = MAX_BUL_TME;
            }
            if (XCI.GetButton(XboxButton.Y, playerNumber))
            {
                Instantiate(laserYPrefab, transform.position, laserYPrefab.transform.rotation);
                bulletTimer = MAX_BUL_TME;
            }
        }

        // Left stick movement
        newPosition = transform.position;
        float axisX   = XCI.GetAxis(XboxAxis.LeftStickX, playerNumber);
        float axisY   = XCI.GetAxis(XboxAxis.LeftStickY, playerNumber);
        float newPosX = newPosition.x + (axisX * maxMoveSpeed * Time.deltaTime);
        float newPosZ = newPosition.z + (axisY * maxMoveSpeed * Time.deltaTime);

        newPosition        = new Vector3(newPosX, transform.position.y, newPosZ);
        transform.position = newPosition;


        // Right stick movement
        newPosition        = transform.position;
        axisX              = XCI.GetAxis(XboxAxis.RightStickX, playerNumber);
        axisY              = XCI.GetAxis(XboxAxis.RightStickY, playerNumber);
        newPosX            = newPosition.x + (axisX * maxMoveSpeed * 0.3f * Time.deltaTime);
        newPosZ            = newPosition.z + (axisY * maxMoveSpeed * 0.3f * Time.deltaTime);
        newPosition        = new Vector3(newPosX, transform.position.y, newPosZ);
        transform.position = newPosition;


        // D-Pad testing
        if (dpUpBulletTimer > 0.0f)
        {
            dpUpBulletTimer -= Time.deltaTime;
        }
        if (dpDownBulletTimer > 0.0f)
        {
            dpDownBulletTimer -= Time.deltaTime;
        }
        if (dpLeftBulletTimer > 0.0f)
        {
            dpLeftBulletTimer -= Time.deltaTime;
        }
        if (dpRightBulletTimer > 0.0f)
        {
            dpRightBulletTimer -= Time.deltaTime;
        }
        if (dpUpBulletTimer <= 0.0f)
        {
            if (XCI.GetDPad(XboxDPad.Up, playerNumber))
            {
                bulletReference = Instantiate(laserBumpPrefab, transform.position, laserYPrefab.transform.rotation) as GameObject;
                bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f);
                dpUpBulletTimer = MAX_BUL_TME * 2;
            }
        }
        if (dpDownBulletTimer <= 0.0f)
        {
            if (XCI.GetDPad(XboxDPad.Down, playerNumber))
            {
                bulletReference = Instantiate(laserBumpPrefab, transform.position, laserAPrefab.transform.rotation) as GameObject;
                bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f);
                dpDownBulletTimer = MAX_BUL_TME * 2;
            }
        }
        if (dpLeftBulletTimer <= 0.0f)
        {
            if (XCI.GetDPad(XboxDPad.Left, playerNumber))
            {
                bulletReference = Instantiate(laserBumpPrefab, transform.position, laserXPrefab.transform.rotation) as GameObject;
                bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f);
                dpLeftBulletTimer = MAX_BUL_TME * 2;
            }
        }
        if (dpRightBulletTimer <= 0.0f)
        {
            if (XCI.GetDPad(XboxDPad.Right, playerNumber))
            {
                bulletReference = Instantiate(laserBumpPrefab, transform.position, laserBPrefab.transform.rotation) as GameObject;
                bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 1.0f);
                dpRightBulletTimer = MAX_BUL_TME * 2;
            }
        }


        // Trigger input
        float trigSclX        = triggerLeftPrefab.transform.localScale.x;
        float trigSclZ        = triggerLeftPrefab.transform.localScale.z;
        float leftTrigHeight  = MAX_TRG_SCL * (1.0f - XCI.GetAxis(XboxAxis.LeftTrigger, playerNumber));
        float rightTrigHeight = MAX_TRG_SCL * (1.0f - XCI.GetAxis(XboxAxis.RightTrigger, playerNumber));

        triggerLeftPrefab.transform.localScale  = new Vector3(trigSclX, leftTrigHeight, trigSclZ);
        triggerRightPrefab.transform.localScale = new Vector3(trigSclX, rightTrigHeight, trigSclZ);


        // Bumper input
        if (XCI.GetButtonDown(XboxButton.LeftBumper, playerNumber))
        {
            Instantiate(laserBumpPrefab, triggerLeftPrefab.transform.position, laserBumpPrefab.transform.rotation);
        }
        if (XCI.GetButtonDown(XboxButton.RightBumper, playerNumber))
        {
            Instantiate(laserBumpPrefab, triggerRightPrefab.transform.position, laserBumpPrefab.transform.rotation);
        }


        // Start and back, same as bumpers but smaller bullets
        if (XCI.GetButtonUp(XboxButton.Back, playerNumber))
        {
            bulletReference = Instantiate(laserBumpPrefab, triggerLeftPrefab.transform.position, laserBumpPrefab.transform.rotation) as GameObject;
            bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        }
        if (XCI.GetButtonUp(XboxButton.Start, playerNumber))
        {
            bulletReference = Instantiate(laserBumpPrefab, triggerRightPrefab.transform.position, laserBumpPrefab.transform.rotation) as GameObject;
            bulletReference.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        }


        // To quit the program (with keyboard)
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
Beispiel #6
0
    private void UpdateCtrl_XCI()
    {
        Vector2 vec = new Vector2();

        // Left Stick
        if (XCI.GetButtonDown(XboxButton.LeftStick, m_Ctrler))
        {
        }

        // Right Stick
        if (XCI.GetButtonDown(XboxButton.RightStick, m_Ctrler))
        {
        }

        // Left stick movement
        float axisLX = XCI.GetAxis(XboxAxis.LeftStickX, m_Ctrler);
        float axisLY = XCI.GetAxis(XboxAxis.LeftStickY, m_Ctrler);

        vec.x = axisLX;
        vec.y = axisLY;
        if (vec.magnitude > m_MinStickDragDis)
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Move, vec);
        }
        else
        {
            InputManager.instance.InputCommand(m_Role, CommandType.StopMove);
        }

        // Right stick movement
        float axisRX = XCI.GetAxis(XboxAxis.RightStickX, m_Ctrler);
        float axisRY = XCI.GetAxis(XboxAxis.RightStickY, m_Ctrler);

        vec.x = axisRX;
        vec.y = axisRY;
        if (vec.magnitude > m_MinStickDragDis)
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Attack, vec);
        }
        else
        {
            InputManager.instance.InputCommand(m_Role, CommandType.StopAttack);
            InputManager.instance.InputCommand(m_Role, CommandType.CastAttack);
        }

        // D-Pad
        if (XCI.GetDPad(XboxDPad.Up, m_Ctrler))
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Move, Vector2.up);
        }
        if (XCI.GetDPad(XboxDPad.Down, m_Ctrler))
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Move, Vector2.down);
        }
        if (XCI.GetDPad(XboxDPad.Left, m_Ctrler))
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Move, Vector2.left);
        }
        if (XCI.GetDPad(XboxDPad.Right, m_Ctrler))
        {
            InputManager.instance.InputCommand(m_Role, CommandType.Move, Vector2.right);
        }
        if (XCI.GetDPadUp(XboxDPad.Up, m_Ctrler) || XCI.GetDPadUp(XboxDPad.Down, m_Ctrler) ||
            XCI.GetDPadUp(XboxDPad.Left, m_Ctrler) || XCI.GetDPadUp(XboxDPad.Right, m_Ctrler))
        {
            InputManager.instance.InputCommand(m_Role, CommandType.StopMove);
        }

        // A,B,X,Y
        if (XCI.GetButton(XboxButton.A, m_Ctrler))
        {
            // InputManager.instance.InputCommand(m_Role, CommandType.Attack, Vector2.down);
            m_Role.EnsureTransmission();
        }
        // if (XCI.GetButton(XboxButton.B, m_Ctrler))
        // {
        //     InputManager.instance.InputCommand(m_Role, CommandType.Attack, Vector2.right);
        // }
        // if (XCI.GetButton(XboxButton.X, m_Ctrler))
        // {
        //     InputManager.instance.InputCommand(m_Role, CommandType.Attack, Vector2.left);
        // }
        // if (XCI.GetButton(XboxButton.Y, m_Ctrler))
        // {
        //     InputManager.instance.InputCommand(m_Role, CommandType.Attack, Vector2.up);
        // }
        // if (XCI.GetButtonUp(XboxButton.A, m_Ctrler) || XCI.GetButtonUp(XboxButton.B, m_Ctrler) ||
        // XCI.GetButtonUp(XboxButton.X, m_Ctrler) || XCI.GetButtonUp(XboxButton.Y, m_Ctrler))
        // {
        //     InputManager.instance.InputCommand(m_Role, CommandType.StopAttack);
        //     InputManager.instance.InputCommand(m_Role, CommandType.CastAttack);
        // }

        // Trigger input
        float trigL = XCI.GetAxis(XboxAxis.LeftTrigger, m_Ctrler);
        float trigR = XCI.GetAxis(XboxAxis.RightTrigger, m_Ctrler);

        // Bumper input
        if (XCI.GetButtonDown(XboxButton.LeftBumper, m_Ctrler))
        {
        }
        if (XCI.GetButtonDown(XboxButton.RightBumper, m_Ctrler))
        {
        }

        // Start and back, same as bumpers but smaller bullets
        if (XCI.GetButtonUp(XboxButton.Back, m_Ctrler))
        {
        }
        if (XCI.GetButtonUp(XboxButton.Start, m_Ctrler))
        {
        }
    }
    public void MyUpdate()
    {
        Vector2 vec = new Vector2();

        // Left Stick
        if (XCI.GetButtonDown(XboxButton.LeftStick, m_Ctrler))
        {
        }

        // Right Stick
        if (XCI.GetButtonDown(XboxButton.RightStick, m_Ctrler))
        {
        }

        // Left stick movement
        float axisLX = XCI.GetAxis(XboxAxis.LeftStickX, m_Ctrler);
        float axisLY = XCI.GetAxis(XboxAxis.LeftStickY, m_Ctrler);

        vec.x = axisLX;
        vec.y = axisLY;
        if (vec.magnitude > m_MinStickDragDis)
        {
            m_Role.Move(vec);
            Global.instance.MyUpdate();
        }

        // Right stick movement
        float axisRX = XCI.GetAxis(XboxAxis.RightStickX, m_Ctrler);
        float axisRY = XCI.GetAxis(XboxAxis.RightStickY, m_Ctrler);

        vec.x = axisRX;
        vec.y = axisRY;
        if (vec.magnitude > m_MinStickDragDis)
        {
            // m_Role.Turn(vec);
            // m_Role.Shoot();
        }


        // D-Pad
        if (XCI.GetDPad(XboxDPad.Up, m_Ctrler))
        {
            // m_Role.Move(Vector2.up);
        }
        if (XCI.GetDPad(XboxDPad.Down, m_Ctrler))
        {
            // m_Role.Move(Vector2.down);
        }
        if (XCI.GetDPad(XboxDPad.Left, m_Ctrler))
        {
            // m_Role.Move(Vector2.left);
        }
        if (XCI.GetDPad(XboxDPad.Right, m_Ctrler))
        {
            // m_Role.Move(Vector2.right);
        }


        // A,B,X,Y
        if (XCI.GetButton(XboxButton.A, m_Ctrler))
        {
            // m_Role.Turn(Vector2.down);
            // m_Role.Shoot();
        }
        if (XCI.GetButton(XboxButton.B, m_Ctrler))
        {
            // m_Role.Turn(Vector2.right);
            // m_Role.Shoot();
        }
        if (XCI.GetButton(XboxButton.X, m_Ctrler))
        {
            // m_Role.Turn(Vector2.left);
            // m_Role.Shoot();
        }
        if (XCI.GetButton(XboxButton.Y, m_Ctrler))
        {
            // m_Role.Turn(Vector2.up);
            // m_Role.Shoot();
        }

        // Trigger input
        float trigL = XCI.GetAxis(XboxAxis.LeftTrigger, m_Ctrler);
        float trigR = XCI.GetAxis(XboxAxis.RightTrigger, m_Ctrler);

        // Bumper input
        if (XCI.GetButtonDown(XboxButton.LeftBumper, m_Ctrler))
        {
        }
        if (XCI.GetButtonDown(XboxButton.RightBumper, m_Ctrler))
        {
        }

        // Start and back, same as bumpers but smaller bullets
        if (XCI.GetButtonUp(XboxButton.Back, m_Ctrler))
        {
        }
        if (XCI.GetButtonUp(XboxButton.Start, m_Ctrler))
        {
        }
    }
Beispiel #8
0
    // Update is called once per frame
    void Update()
    {
        //True if the player is out of enemy sight for cool down amount of time.
        if (wasSeen == true && timeStamp <= Time.time)
        {
            safeFromGuard();
        }

        //Used to determine the rotation of the sprite.
        Vector3 _origPos = transform.position;

        //Xbox Controller (works with all players)
        if (XCI.GetDPad(XboxDPad.Up, PlayerNumber) && canMove[2])
        {
            transform.position += new Vector3(0, 1, 0) * speed * Time.deltaTime;
            canMove[0]          = true;
            canMove[1]          = true;
            canMove[3]          = true;
        }
        else if (XCI.GetDPad(XboxDPad.Down, PlayerNumber) && canMove[3])
        {
            transform.position += new Vector3(0, -1, 0) * speed * Time.deltaTime;
            canMove[0]          = true;
            canMove[1]          = true;
            canMove[2]          = true;
        }
        else if (XCI.GetDPad(XboxDPad.Left, PlayerNumber) && canMove[0])
        {
            transform.position += new Vector3(-1, 0, 0) * speed * Time.deltaTime;
            canMove[1]          = true;
            canMove[2]          = true;
            canMove[3]          = true;
        }
        else if (XCI.GetDPad(XboxDPad.Right, PlayerNumber) && canMove[1])
        {
            transform.position += new Vector3(1, 0, 0) * speed * Time.deltaTime;
            canMove[0]          = true;
            canMove[2]          = true;
            canMove[3]          = true;
        }

        //Debug mode
        //Player 1 controls
        if (PlayerNumber == 1)
        {
            if (Input.GetButton("Player1Up") && canMove[2])
            {
                transform.position += new Vector3(0, 1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player1Down") && canMove[3])
            {
                transform.position += new Vector3(0, -1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[2]          = true;
            }
            else if (Input.GetButton("Player1Left") && canMove[0])
            {
                transform.position += new Vector3(-1, 0, 0) * speed * Time.deltaTime;
                canMove[1]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player1Right") && canMove[1])
            {
                transform.position += new Vector3(1, 0, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
        }

        //Player 2 controls
        if (PlayerNumber == 2)
        {
            if (Input.GetButton("Player2Up") && canMove[2])
            {
                transform.position += new Vector3(0, 1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player2Down") && canMove[3])
            {
                transform.position += new Vector3(0, -1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[2]          = true;
            }
            else if (Input.GetButton("Player2Left") && canMove[0])
            {
                transform.position += new Vector3(-1, 0, 0) * speed * Time.deltaTime;
                canMove[1]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player2Right") && canMove[1])
            {
                transform.position += new Vector3(1, 0, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
        }

        //Player 3 controls
        if (PlayerNumber == 3)
        {
            if (Input.GetButton("Player3Up") && canMove[2])
            {
                transform.position += new Vector3(0, 1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player3Down") && canMove[3])
            {
                transform.position += new Vector3(0, -1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[2]          = true;
            }
            else if (Input.GetButton("Player3Left") && canMove[0])
            {
                transform.position += new Vector3(-1, 0, 0) * speed * Time.deltaTime;
                canMove[1]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player3Right") && canMove[1])
            {
                transform.position += new Vector3(1, 0, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
        }

        //Player 4 controls
        if (PlayerNumber == 4)
        {
            if (Input.GetButton("Player4Up") && canMove[2])
            {
                transform.position += new Vector3(0, 1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player4Down") && canMove[3])
            {
                transform.position += new Vector3(0, -1, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[1]          = true;
                canMove[2]          = true;
            }
            else if (Input.GetButton("Player4Left") && canMove[0])
            {
                transform.position += new Vector3(-1, 0, 0) * speed * Time.deltaTime;
                canMove[1]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
            else if (Input.GetButton("Player4Right") && canMove[1])
            {
                transform.position += new Vector3(1, 0, 0) * speed * Time.deltaTime;
                canMove[0]          = true;
                canMove[2]          = true;
                canMove[3]          = true;
            }
        }

        Vector3 moveDirection = transform.position - _origPos;

        //Determine the rotation of the sprite.
        if (moveDirection != Vector3.zero)
        {
            angle = Mathf.Round(Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg) - 90;             //-90 needed as the rotation of the sprite is offset by 90 degree.
            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
    }
 public override bool GetButtonCurrentState()
 {
     // As XboxJoystickDPad is an exact copy of XboxDPad
     // in this implementation, I can just cast the enum.
     return(XCI.GetDPad((XboxDPad)this.button));
 }
    /*
     * Brief: manage the horizontal movement of the player
     */
    void Update()
    {
        // if the player is alive
        if (m_cameraMovement.m_playerAlive)
        {
            m_direction = 0.0f;
            if (Input.GetAxis("Horizontal") > m_inputThreshold || XCI.GetDPad(XboxDPad.Right))
            {
                m_direction = 1.0f;
            }
            else if (Input.GetAxis("Horizontal") < -m_inputThreshold || XCI.GetDPad(XboxDPad.Left))
            {
                m_direction = -1.0f;
            }

            //Sets moveVelocity's x to - or + move speed
            m_moveVelocity.x = m_direction * m_currentAcceleration;

            //Sets ray position to the left or right side of player
            if (m_moveVelocity.x > 0 && m_rayPosition.x < 0.0f)
            {
                m_rayPosition.x = m_playerDimensions.x + m_minWallDistance;
            }
            else if (m_moveVelocity.x < 0 && m_rayPosition.x > 0.0f)
            {
                m_rayPosition.x = -m_playerDimensions.x - m_minWallDistance;
            }

            //Increases velocity by the move velocity
            m_rb2d.velocity += m_moveVelocity;

            //If jump is pressed set max aerial speed to current x velocity
            if (Input.GetButtonDown("Jump") || XCI.GetButtonDown(XboxButton.A))
            {
                m_aerialMaxSpeed = Mathf.Abs(m_rb2d.velocity.x);
            }

            //Checks if x velocity is greater than max speed in either direction
            if (m_rb2d.velocity.x > m_maxSpeed || m_rb2d.velocity.x < -m_maxSpeed)
            {
                // set the player's speed to the max speed of the direction it is moving
                m_maxVelocity.Set(((m_rb2d.velocity.x >= 0) ? 1 : -1) * m_maxSpeed, m_rb2d.velocity.y);
                m_rb2d.velocity = m_maxVelocity;
            }

            //Checks if the player is in the air
            if (m_playJump.m_inAir)
            {
                m_currentAcceleration = m_airAcceleration;
                //Sets the aerialMaxSpeed to the minimum
                if (m_aerialMaxSpeed < m_minimumMaxAirSpeed)
                {
                    m_aerialMaxSpeed = m_minimumMaxAirSpeed;
                }
                //Checks if x velocity is greater than max speed
                if (Mathf.Abs(m_rb2d.velocity.x) > m_aerialMaxSpeed)
                {
                    // set the player's speed to the max speed of the direction it is moving
                    m_maxVelocity.Set(((m_rb2d.velocity.x >= 0) ? 1 : -1) * m_aerialMaxSpeed, m_rb2d.velocity.y);
                    m_rb2d.velocity = m_maxVelocity;
                }
            }
            //Resets current speed back to ground speed
            else
            {
                m_currentAcceleration = m_groundAcceleration;

                // determine what the max aerial speed would be for if the player were to fall of a platform without jumping
                m_aerialMaxSpeed = Mathf.Abs(m_rb2d.velocity.x);
            }

            if (m_rb2d.velocity.x > 0.0f && gameObject.transform.rotation.eulerAngles.y > 90.0f)
            {
                gameObject.transform.rotation = m_right;
            }
            else if (m_rb2d.velocity.x < 0.0f && gameObject.transform.rotation.eulerAngles.y < 90.0f)
            {
                gameObject.transform.rotation = m_left;
            }

            // draw a raycast adjacent to the player, in the direction they are moving
            m_rayRH2D = Physics2D.Raycast(gameObject.transform.position + m_rayPosition, gameObject.transform.up, m_playerDimensions.y - m_yRayOffset);

            //Debug.DrawRay(gameObject.transform.position + m_rayPosition, gameObject.transform.up, Color.magenta);

            // if the raycast collides with a platform, the player is hitting a wall
            if (m_rayRH2D.collider != null && m_rayRH2D.collider.gameObject.tag == "Platform")
            {
                // set the player's horizontal velocity to 0
                m_wallHit.y     = m_rb2d.velocity.y;
                m_rb2d.velocity = m_wallHit;
            }
        }
        m_animator.SetFloat("X_Velocity", Mathf.Round(m_rb2d.velocity.x * 100f) / 100f);
    }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        // if (XCI.GetButtonUp(XboxButton.Start)) {
        //  print("YES");
        // }

        //************ COMMENTED OUT DUE TO CTRLR ERROR

        if (Input.GetKeyDown(KeyCode.Escape) || XCI.GetButtonDown(XboxButton.Start))
        {
            //*********************************
            // if (Input.GetKeyDown("escape") || Input.GetButtonDown("Start Button")) {
            SetPausedGame();
            if (playableLevel)
            {
                curtain.SwitchPausedGame();
            }
        }

        if (paused && !demoMode)
        {
            if ((Input.GetKeyDown(KeyCode.DownArrow) || Input.GetAxis("Vertical") < 0f || XCI.GetDPad(XboxDPad.Down)) && !onQuit)
            {
                onQuit = true;
                arrow.transform.localPosition = new Vector2(arrow.transform.localPosition.x, arrow.transform.localPosition.y - menuDist);
            }
            if ((Input.GetKeyDown(KeyCode.UpArrow) || Input.GetAxis("Vertical") > 0f || XCI.GetDPad(XboxDPad.Up)) && onQuit)
            {
                onQuit = false;
                arrow.transform.localPosition = new Vector2(arrow.transform.localPosition.x, arrow.transform.localPosition.y + menuDist);
            }

            //************ COMMENTED OUT DUE TO CTRLR ERROR
            if ((Input.GetKeyDown("space") || XCI.GetButton(XboxButton.A)) && !onQuit)
            {
                // if ((Input.GetKeyDown("space") || Input.GetKeyDown(KeyCode.JoystickButton0)) && onQuit) {
                SetPausedGame();

                if (playableLevel)
                {
                    curtain.SwitchPausedGame();
                }
            }

            //************ COMMENTED OUT DUE TO CTRLR ERROR
            if ((Input.GetKeyDown("space") || XCI.GetButton(XboxButton.A)) && onQuit)
            {
                // if ((Input.GetKeyDown("space") || Input.GetKeyDown(KeyCode.JoystickButton0)) && onQuit) {
                //USED FOR WARD GAMES LAUNCHER

                // try {
                //  Process myProcess = new Process();
                //        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                //        myProcess.StartInfo.CreateNoWindow = false;
                //        // myProcess.StartInfo.UseShellExecute = false;
                //        myProcess.StartInfo.FileName = "C:\\Users\\Dylan\\Desktop\\BnP\\Launcher\\Launcher.exe";
                //        myProcess.Start();
                //    }
                //    catch (Exception e) {
                //           Console.WriteLine(e.Message);
                //       }

                Application.Quit();
            }
        }

        else if (paused && demoMode)
        {
            if (XCI.GetButtonUp(XboxButton.A) || XCI.GetButtonUp(XboxButton.B))
            {
                // if (Input.GetButtonDown("A Button") || Input.GetButtonDown("B Button")) {
                SetPausedGame();
                if (playableLevel)
                {
                    curtain.SwitchPausedGame();
                }
            }
            //reload level
            else if (XCI.GetButtonUp(XboxButton.X))
            {
                // else if (Input.GetButtonDown("X Button")) {
                Time.timeScale = 1f;
                IntersceneDataHandler.startedTutorial = false;
                IntersceneDataHandler.currentLevel    = 0;
                Application.LoadLevel(Application.loadedLevel);
            }

            else if (XCI.GetButtonUp(XboxButton.Y))
            {
                // else if (Input.GetButtonDown("Y Button")) {
                Time.timeScale = 1f;
                Application.LoadLevel(0);
            }

            // else if (XCI.GetButtonUp(XboxButton.LeftBumper)) {
            // // else if (Input.GetButtonDown("Left Bumper")) {
            //  Time.timeScale = 1f;
            //  Application.LoadLevel(4);
            // }

            else if (XCI.GetButtonUp(XboxButton.RightBumper))
            {
                Time.timeScale = 1f;
                SceneManager.LoadScene("Level Select");
            }
        }
    }