Beispiel #1
0
    void Update()
    {
        //new button press detection
        //upPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index);
        upPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index);

        if (!lastUpPressed && upPressed)
        {
            //if it wasnt pressed last time but it is now
            lastUpPressed = true;         //log that it is pressed now for the next cycle
            upPressed     = true;         //signal new button press
        }
        else
        {
            lastUpPressed = upPressed;     //log the current state for next cycle
            upPressed     = false;         //signal no new button press
        }

        //downPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index);
        downPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index);

        if (!lastDownPressed && downPressed)
        {
            //if it wasnt pressed last time but it is now
            lastDownPressed = true;         //log that it is pressed now for the next cycle
            downPressed     = true;         //signal new button press
        }
        else
        {
            lastDownPressed = downPressed;   //log the current state for next cycle
            downPressed     = false;         //signal no new button press
        }

        //new joystick tilt detection
        //get the raw tilts to bools
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) < -L_STICK_DEADZONE)
        {
            lJoyUp = true;
        }
        else
        {
            lJoyUp = false;
        }
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) > L_STICK_DEADZONE)
        {
            lJoyDown = true;
        }
        else
        {
            lJoyDown = false;
        }

        //evaluate new tilts
        if (!lastLJoyUp && lJoyUp)
        {
            //if it wasnt up last time but it is now
            lastLJoyUp = true;         //log that it is up now for the next cycle
            lJoyUp     = true;         //signal new up tilt
        }
        else
        {
            lastLJoyUp = lJoyUp;        //log the current state for next cycle
            lJoyUp     = false;         //signal no new joystick tilt
        }

        if (!lastLJoyDown && lJoyDown)
        {
            //if it wasnt up last time but it is now
            lastLJoyDown = true;         //log that it is up now for the next cycle
            lJoyDown     = true;         //signal new joystick tilt
        }
        else
        {
            lastLJoyDown = lJoyDown;      //log the current state for next cycle
            lJoyDown     = false;         //signal no new joystick tilt
        }

        //select button
        //selectPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_O, Index);
        selectPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index);

        //exit shortcut
        if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index))
        {
            Application.LoadLevel("Main Menu");
        }


        //what to do if a choice is selected
        if (selectPressed)
        {
            OuyaSDK.Purchasable toBeBought = new OuyaSDK.Purchasable();
            switch (selectedChoice)
            {
            case 0:
                toBeBought.productId = "1";
                OuyaSDK.requestPurchase(toBeBought);

                break;

            case 1:
                toBeBought.productId = "2";
                OuyaSDK.requestPurchase(toBeBought);
                break;

            case 2:
                toBeBought.productId = "5";
                OuyaSDK.requestPurchase(toBeBought);
                break;

            case 3:
                Application.LoadLevel("Main Menu");
                break;

            default:
                break;
            }
        }

        //handling choice movement
        if ((upPressed || lJoyUp) && (selectedChoice > 0))
        {
            selectedChoice -= 1;
        }

        if ((downPressed || lJoyDown) && (selectedChoice < (choices.Length - 1)))
        {
            selectedChoice += 1;
        }
    }
Beispiel #2
0
    void Update()
    {
        //new button press detection
        //rightPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index);
        rightPressed = (Input.GetKey(KeyCode.LeftArrow) ||
                        OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_LEFT, Index));

        if (!lastRightPressed && rightPressed)
        {
            //if it wasnt pressed last time but it is now
            lastRightPressed = true;         //log that it is pressed now for the next cycle
            rightPressed     = true;         //signal new button press
        }
        else
        {
            lastRightPressed = rightPressed;  //log the current state for next cycle
            rightPressed     = false;         //signal no new button press
        }

        //leftPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index);
        leftPressed = (Input.GetKey(KeyCode.RightArrow) ||
                       OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_RIGHT, Index));

        if (!lastLeftPressed && leftPressed)
        {
            //if it wasnt pressed last time but it is now
            lastLeftPressed = true;         //log that it is pressed now for the next cycle
            leftPressed     = true;         //signal new button press
        }
        else
        {
            lastLeftPressed = leftPressed;   //log the current state for next cycle
            leftPressed     = false;         //signal no new button press
        }

        //new joystick tilt detection
        //get the raw tilts to bools
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_X, Index) < -L_STICK_DEADZONE)
        {
            lJoyRight = true;
        }
        else
        {
            lJoyRight = false;
        }
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_X, Index) > L_STICK_DEADZONE)
        {
            lJoyLeft = true;
        }
        else
        {
            lJoyLeft = false;
        }

        //evaluate new tilts
        if (!lastLJoyRight && lJoyRight)
        {
            //if it wasnt up last time but it is now
            lastLJoyRight = true;         //log that it is up now for the next cycle
            lJoyRight     = true;         //signal new up tilt
        }
        else
        {
            lastLJoyRight = lJoyRight;     //log the current state for next cycle
            lJoyRight     = false;         //signal no new joystick tilt
        }

        if (!lastLJoyLeft && lJoyLeft)
        {
            //if it wasnt up last time but it is now
            lastLJoyLeft = true;         //log that it is up now for the next cycle
            lJoyLeft     = true;         //signal new joystick tilt
        }
        else
        {
            lastLJoyLeft = lJoyLeft;      //log the current state for next cycle
            lJoyLeft     = false;         //signal no new joystick tilt
        }

        //select button
        //selectPressed = OuyaExampleCommon.GetButtonLeft (OuyaSDK.KeyEnum.BUTTON_O, Index);

        //controllerShare button
        if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_U, Index))
        {
            controllerShareOn = !controllerShareOn;
        }

        //exit shortcut
        if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index) ||
            Input.GetKeyDown(KeyCode.Backspace))
        {
            Application.LoadLevel("Main Menu");
        }


        //what to do if a choice is selected
        switch (selectedChoice)
        {
        case 3:

            break;

        case 2:

            break;

        case 1:

            break;

        default:

            break;
        }

        //bird renderers
        if (playersReady [1])
        {
            bird2.renderer.enabled = true;
        }
        else
        {
            bird2.renderer.enabled = false;
        }
        if (playersReady [2])
        {
            bird3.renderer.enabled = true;
        }
        else
        {
            bird3.renderer.enabled = false;
        }
        if (playersReady [3])
        {
            bird4.renderer.enabled = true;
        }
        else
        {
            bird4.renderer.enabled = false;
        }

        numberOfPlayers = selectedChoice + 1;
        setPlayers(numberOfPlayers);
        PlayerPrefs.SetInt("numberOfPlayers", numberOfPlayers);


        //handling choice movement
        if ((rightPressed || lJoyRight) && (selectedChoice > 0))
        {
            selectedChoice -= 1;
        }

        if ((leftPressed || lJoyLeft) && (selectedChoice < (choices.Length - 1)))
        {
            selectedChoice += 1;
        }

        //p1 O button to start game
        if (Input.GetKeyDown("space") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index) ||
            OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index) ||
            OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index))
        {
            print("got it");
            //everybody in
            if (compare4Bools())
            {
                //save controllerShare options
                if (controllerShareOn)
                {
                    PlayerPrefs.SetInt("controllerShare", 1);
                }
                else
                {
                    PlayerPrefs.SetInt("controllerShare", 0);
                }

                PlayerPrefs.SetInt("numberOfPlayers", numberOfPlayers);
                PlayerPrefs.Save();
                Application.LoadLevel("Game Level");
            }
        }

        //ready up buttons
        if (controllerShareOn)
        {
            //yes controller share ready up

            //p2 ready up
            if (Input.GetKeyDown("a") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index) ||
                OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index))
            {
                if (playersOn[1])
                {
                    playersReady[1] = true;
                }
            }

            //p3 ready up
            if (Input.GetKeyDown("'") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2) ||
                OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index2) ||
                OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index2))
            {
                if (playersOn[2])
                {
                    playersReady[2] = true;
                }
            }

            //p4 ready up
            if (Input.GetKeyDown("5") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index2) ||
                OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index2))
            {
                if (playersOn[3])
                {
                    playersReady[3] = true;
                }
            }
        }
        else
        {
            //no controller share ready up

            //p2 ready up
            if (Input.GetKeyDown("a") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2))
            {
                if (playersOn[1])
                {
                    playersReady[1] = true;
                }
            }

            //p3 ready up
            if (Input.GetKeyDown("'") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index3))
            {
                if (playersOn[2])
                {
                    playersReady[2] = true;
                }
            }

            //p4 ready up
            if (Input.GetKeyDown("5") || OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index4))
            {
                if (playersOn[3])
                {
                    playersReady[3] = true;
                }
            }
        }

        //controllerShareState catcher
        if ((controllerShareOn != controllerShareLastState) && controllerShareLastState)
        {
            //if state changed and it used to be on
            controllerShareJustOn = true;

            //controllerShare was just turned off so set players to one to avoid dummy players signed in
            selectedChoice = 0;
        }
        else
        {
            controllerShareJustOn = false;
        }

        //auto move to 2 player when turning on controllershare
        if ((controllerShareOn != controllerShareLastState) && !controllerShareLastState)
        {
            //controllerShare was just turned on so set the game to two player
            selectedChoice = 1;
        }

        controllerShareLastState = controllerShareOn; //log current state as last
    }                                                 //end void Update()
Beispiel #3
0
    void Update()
    {
        //new button press detection
        //upPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index);
        upPressed = (Input.GetKey("up") ||
                     OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_UP, Index));

        if (!lastUpPressed && upPressed)
        {
            //if it wasnt pressed last time but it is now
            lastUpPressed = true;         //log that it is pressed now for the next cycle
            upPressed     = true;         //signal new button press
        }
        else
        {
            lastUpPressed = upPressed;     //log the current state for next cycle
            upPressed     = false;         //signal no new button press
        }

        //downPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index);
        downPressed = (Input.GetKey("down") ||
                       OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_DPAD_DOWN, Index));

        if (!lastDownPressed && downPressed)
        {
            //if it wasnt pressed last time but it is now
            lastDownPressed = true;         //log that it is pressed now for the next cycle
            downPressed     = true;         //signal new button press
        }
        else
        {
            lastDownPressed = downPressed;   //log the current state for next cycle
            downPressed     = false;         //signal no new button press
        }

        //new joystick tilt detection
        //get the raw tilts to bools
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) < -L_STICK_DEADZONE)
        {
            lJoyUp = true;
        }
        else
        {
            lJoyUp = false;
        }
        if (OuyaExampleCommon.GetAxisRaw(OuyaSDK.KeyEnum.AXIS_LSTICK_Y, Index) > L_STICK_DEADZONE)
        {
            lJoyDown = true;
        }
        else
        {
            lJoyDown = false;
        }

        //evaluate new tilts
        if (!lastLJoyUp && lJoyUp)
        {
            //if it wasnt up last time but it is now
            lastLJoyUp = true;         //log that it is up now for the next cycle
            lJoyUp     = true;         //signal new up tilt
        }
        else
        {
            lastLJoyUp = lJoyUp;        //log the current state for next cycle
            lJoyUp     = false;         //signal no new joystick tilt
        }

        if (!lastLJoyDown && lJoyDown)
        {
            //if it wasnt up last time but it is now
            lastLJoyDown = true;         //log that it is up now for the next cycle
            lJoyDown     = true;         //signal new joystick tilt
        }
        else
        {
            lastLJoyDown = lJoyDown;      //log the current state for next cycle
            lJoyDown     = false;         //signal no new joystick tilt
        }

        //select button
        //selectPressed = OuyaExampleCommon.GetButtonDown (OuyaSDK.KeyEnum.BUTTON_O, Index);
        selectPressed = (Input.GetKeyDown("space") ||
                         OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index));

        //back shortcut
        if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index))
        {
            saveAndGoBack();
        }


        //what to do if a choice is selected
        if (selectPressed)
        {
            switch (selectedChoice)
            {
            case 0:
                toggles[0] = flipInt(toggles[0]);
                break;

            case 1:
                toggles[1] = flipInt(toggles[1]);
                break;

            case 2:
                toggles[2] = flipInt(toggles[2]);
                break;

            case 3:
                saveAndGoBack();
                break;

            default:
                break;
            }
        }

        //handling choice movement
        if ((upPressed || lJoyUp) && (selectedChoice > 0))
        {
            selectedChoice -= 1;
        }

        if ((downPressed || lJoyDown) && (selectedChoice < (choices.Length - 1)))
        {
            selectedChoice += 1;
        }
    }