Example #1
0
    void Update()
    {
        //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) || Input.GetKeyDown(KeyCode.Backspace))
        {
            saveAndGoBack();
        }


        //what to do if a choice is selected
        if (selectPressed)
        {
            saveAndGoBack();
        }
    }
Example #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()
Example #3
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;
        }
    }
Example #4
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 = Input.GetKeyDown("down");
        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 = Input.GetKeyDown("space");
        selectPressed = OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index);

        //exit shortcut
        if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index))
        {
            Application.Quit();
        }


        //what to do if a choice is selected
        if (selectPressed)
        {
            switch (selectedChoice)
            {
            case 0:
                Application.LoadLevel("Player Select");
                break;

            case 1:
                Application.LoadLevel("Options");
                break;

            case 2:
                Application.LoadLevel("Credits");
                break;

            case 3:
                Application.LoadLevel("Donate");
                break;

            case 4:
                Application.Quit();
                break;

            default:
                break;
            }
        }

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

        if ((downPressed) && (selectedChoice < (choices.Length - 1)))
        {
            selectedChoice += 1;
        }
    }
Example #5
0
    void OnGUI()
    {
        //print player scores using fallthrough, case is player number
        switch (numberOfPlayers)
        {
        case 4:
            GUI.Label(new Rect(((Screen.width * 4.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird4.getScore().ToString(), p4ScoreStyle);
            goto case 3;

        case 3:
            GUI.Label(new Rect(((Screen.width * 3.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird3.getScore().ToString(), p3ScoreStyle);
            goto case 2;

        case 2:
            GUI.Label(new Rect(((Screen.width * 2.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird2.getScore().ToString(), p2ScoreStyle);
            goto case 1;

        case 1:
            GUI.Label(new Rect(((Screen.width * 1.0f / ((float)numberOfPlayers + 1.0f)) - 50.0f), (Screen.height / 8f), 100, 40), bird1.getScore().ToString(), p1ScoreStyle);
            break;
        }

        //highscore and restart screen
        if (everyBodyDead)
        {
            //Game Over Title
            GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (3.0f / 10.0f) - 20.0f), 100, 40), "Game Over", gameOverTitleStyle);

            if (numberOfPlayers > 1)
            {
                //if there was a tie
                if (getWinningPlayerNumber() == 0.0f)
                {
                    GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "Tie - No Winner", gameOverStyle);
                }
                else
                {
                    //no tie
                    //winning player and score
                    GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "Player " + getWinningPlayerNumber().ToString() + " Wins with " + getWinningPlayerScore() + " Points!", gameOverStyle);
                }
            }
            else
            {
                GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (5.0f / 10.0f) - 20.0f), 100, 40), "You got " + getWinningPlayerScore() + " Points!", gameOverStyle);
            }
            //high score
            if ((getWinningPlayerScore() > PlayerPrefs.GetFloat("highScore")) || newHighScore)
            {
                //new high score!
                newHighScore = true;                    //bool to keep bringing the program through this loop after new high score is saved to playerprefs as high score

                //save high score to playerprefs
                PlayerPrefs.SetFloat("highScore", getWinningPlayerScore());
                PlayerPrefs.Save();

                //print Yay message for new high score
                GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (6.0f / 10.0f) - 20.0f), 100, 40), "New High Score! - " + PlayerPrefs.GetFloat("highScore").ToString(), gameOverStyle);
            }
            else
            {
                //show high score
                GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (6.0f / 10.0f) - 20.0f), 100, 40), "High Score - " + PlayerPrefs.GetFloat("highScore").ToString(), gameOverStyle);
            }

            //replay and back text
            GUI.Label(new Rect(((Screen.width / 2.0f) - 50.0f), (Screen.height * (8.0f / 10.0f) - 20.0f), 100, 40), "    Restart        Back", gameOverStyle);

            GUI.DrawTexture(new Rect(((Screen.width / 2.0f) - 35.0f - 250.0f), ((Screen.height * (8.0f / 10.0f)) - 50.0f), 70, 80), OUYA_O);
            GUI.DrawTexture(new Rect(((Screen.width / 2.0f) - 35.0f + 120.0f), ((Screen.height * (8.0f / 10.0f)) - 50.0f), 70, 80), OUYA_A);

            if (everyBodyDeadTimer > 0.5f)
            {
                //restart
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index))
                {
                    Application.LoadLevel(Application.loadedLevel);
                }
                //back to player select
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_A, Index))
                {
                    Application.LoadLevel("Player Select");
                }
            }
        }
    }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        newPipeTimer += Time.deltaTime;         //add deltatime to pipe counter

        if (everyBodyDead)
        {
            everyBodyDeadTimer += Time.deltaTime;
        }

        //bird input switch
        if (controllerShareOn)
        {
            //yes controllerShare input switch
            switch (numberOfPlayers)
            {
            case 4:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index2) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index2))
                {
                    bird4.SendMessage("Jump");
                }
                goto case 3;

            case 3:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index2) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index2))
                {
                    bird3.SendMessage("Jump");
                }
                goto case 2;

            case 2:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LB, Index) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_LT, Index))
                {
                    bird2.SendMessage("Jump");
                }
                goto case 1;

            case 1:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RT, Index) ||
                    OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_RB, Index))
                {
                    bird1.SendMessage("Jump");
                }
                break;
            }
        }
        else
        {
            //no controller share input switch
            switch (numberOfPlayers)
            {
            case 4:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index4))
                {
                    bird4.SendMessage("Jump");
                }
                goto case 3;

            case 3:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index3))
                {
                    bird3.SendMessage("Jump");
                }
                goto case 2;

            case 2:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index2))
                {
                    bird2.SendMessage("Jump");
                }
                goto case 1;

            case 1:
                if (OuyaExampleCommon.GetButtonDown(OuyaSDK.KeyEnum.BUTTON_O, Index))
                {
                    bird1.SendMessage("Jump");
                }
                break;
            }
        }


        //if it's time to make a new pipe make one
        if (newPipeTimer >= newPipeFrequency && !everyBodyDead)
        {
            //generate a new pipe

            //doubleGapPipe
            if (doublePipeSetsEnabled &&                   //are double pipes even on?
                (numberOfPlayers > 1) &&                   //is this a multiplayer match
                (Random.value < (1f / newPipeDoubleOdds))) //random falls within 1/newPipeDoubleOdds and zero

            //make doubleGapPipeSet
            {
                float randomY = Random.Range(newDoublePipeMinY, newDoublePipeMaxY);
                randomY = Mathf.Round(randomY);

                Instantiate(doubleGapPipeSet,
                            new Vector3(gameObject.transform.position.x + newPipeOffSet,
                                        randomY,
                                        0f),
                            Quaternion.identity);

                newPipeTimer = 0f;                      //reset newPipeTimer counter
            }
            else
            {
                //make singleGapPipeSet
                float randomY = Random.Range(newPipeMinY, newPipeMaxY);
                randomY = Mathf.Round(randomY);

                Instantiate(singleGapPipeSet,
                            new Vector3(gameObject.transform.position.x + newPipeOffSet,
                                        randomY,
                                        0f),
                            Quaternion.identity);

                newPipeTimer = 0f;                      //reset newPipeTimer counter
            }
        }

        //set what bird to follow if all dead just stop moving
        float birdToFollowOffSet = 0;

        if (bird1 != null && bird1.getAlive())
        {
            birdToFollow = bird1;
        }
        else if (bird2 != null && bird2.getAlive())
        {
            birdToFollow       = bird2;
            birdToFollowOffSet = 2;
        }
        else if (bird3 != null && bird3.getAlive())
        {
            birdToFollow       = bird3;
            birdToFollowOffSet = 4;
        }
        else if (bird4 != null && bird4.getAlive())
        {
            birdToFollow       = bird4;
            birdToFollowOffSet = 6;
        }
        else
        {
            everyBodyDead = true;
        }

        //if everyones dead sit still, otherwise follow first living one
        if (!everyBodyDead)
        {
            //camera follow part
            playerPos = birdToFollow.transform.position;

            gameObject.transform.position = new Vector3(playerPos.x + playerXOffset + birdToFollowOffSet,
                                                        gameObject.transform.position.y,
                                                        gameObject.transform.position.z);
        }

        if (everyBodyDead)
        {
            GameOver();
        }
    }
Example #7
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;
        }
    }