示例#1
0
    /**
     * Draws the return button and handles drawing the Quit game pop up if necessary
     */

    void OnGUI()
    {
        // this just handles the menu button in the corner
        if (Time.timeScale != 0)                // don't draw the main menu button if timescale is 0 because this means there is some
        // other user control option up such as game over
        {
            if (GUI.Button(new Rect(Screen.width * x,  //.79f,
                                    Screen.height * y, //0.01822916f,
                                    Screen.width * .09f,
                                    Screen.height * .06f), "", mainMenuStyle))
            {
                if (scence == "Mouth")
                {
                    fp.setPaused();
                }
                Time.timeScale = 0;                             // pause the game
                confirmUp      = true;                          // throw flag
            }
        }

        // if the menu button has been pressed
        if (confirmUp)                          // confirm the user wants to exit to the main menu
        {
            GUI.depth--;

            // draw gui texture that holds box with buttons
            GUI.DrawTexture(new Rect(Screen.width * 0.3193359375f,
                                     Screen.height * 0.28515625f,
                                     Screen.width * 0.3603515625f,
                                     Screen.height * 0.248697917f), confirmPopup);

            // draw "skip game" button
            if (GUI.Button(new Rect(Screen.width * 0.3903f,
                                    Screen.height * 0.41927083f,
                                    Screen.width * 0.1025f,
                                    Screen.height * 0.06640625f), "", confirmYes))
            {
                // if the "skip game" button was pressed
                Time.timeScale = 1;                                                     // unpause the game
                if (level == "SmallIntestineLevel1")
                {
                    GameObject chooseBackground            = GameObject.Find("ChooseBackground");               // find the background chooser
                    SmallIntestineLoadLevelCounter SIlevel = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>();
                    SIlevel.nextLevel();
                    if (SIlevel.getLevel() <= SIlevel.getMaxLevels())
                    {
                        Application.LoadLevel("LoadLevelSmallIntestine");
                    }
                    else
                    {
                        Application.LoadLevel("SmallIntestineEndStoryboard");
                    }
                }
                else
                {
                    Application.LoadLevel(level);                       // return to the main menu
                }
            }

            // draw "keep going" button
            if (GUI.Button(new Rect(Screen.width * 0.51125f,
                                    Screen.height * 0.41927083f,
                                    Screen.width * 0.1025f,
                                    Screen.height * 0.06640625f), "", confirmNo))
            {
                // if the "keep going" button was pressed
                Time.timeScale = 1;                                                     // unpause the game
                if (scence == "Mouth")
                {
                    fp.setPaused();
                }
                confirmUp = false;                                                      // unflag the confirm up variable
            }
        }
    }
示例#2
0
    /**
     * Handles updating all aspects of the game managed here every frame.
     * Sends updated information to the various UI element scripts.
     */
    void Update()
    {
        // check if the game is over
        // if it is just exit because we don't need to go through the rest of the stuff in update
        if (m_IsGameOver)
        {
            return;
        }

        // next check if the user has any health yet because if they don't, the game is over
        if (health <= 0)
        {
            Instantiate(GameOverScript);        // if there is no health start the game over script
            m_IsGameOver = true;                // set the flag in this script to indicate the game is over
        }

        // determine if the game is over because the user won the game
        // we do so by looking for any remaining food blobs alive on the screen and also checking to make sure the
        // script we are reading from is over
        if ((Application.loadedLevelName != "SmallIntestineTutorial" &&
             GameObject.FindWithTag("foodBlobParent") == null && spawnScript.end) ||
            (Application.loadedLevelName == "SmallIntestineTutorial" &&
             GameObject.FindWithTag("foodBlobParentTutorial") == null && spawnScript.end))
        {
            // if the game was over because we won, we need to go to the next level
            // find the background chooser
            GameObject chooseBackground = GameObject.Find("ChooseBackground");
            // get the load level script from the background chooser
            SmallIntestineLoadLevelCounter level = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>();

            level.nextLevel();                          // increase the level count on the load level script

            if (Application.loadedLevelName != "SmallIntestineTutorial")
            {
                Application.LoadLevel("SmallIntestineStats");                   // load the si stats screen
                //SIbps.end();
            }
            else
            {
                Application.LoadLevel("LoadLevelSmallIntestine");                       // otherwise load the next level
            }
        }

        // delay for setting sell to false to allow for race conditions due to order of execution issues
        if (setTowerMenuIsUpFalse)
        {
            elapsedTime += Time.deltaTime;                      // count the time elapsed since last update
            if (elapsedTime > maxElapsedTime)                   // if the elapsed time is greater than the max time we change the isTowerMenuUp variable
            {
                isTowerMenuUp         = false;                  // set isTowerMenuUp to false
                setTowerMenuIsUpFalse = false;                  // change the value of the flag to change isTowerMenuUp to false since it is now changed
                elapsedTime           = 0f;                     // reset the timer for next time
            }
        }

        // draw nutrients text
        nutrientsText.updateText(nutrients);

        // choose face to draw
        if (health > .8 * MAX_HEALTH)
        {
            drawHealthFace.setFace(0);
        }
        else if (health > .6 * MAX_HEALTH)
        {
            drawHealthFace.setFace(1);
        }
        else if (health > .4 * MAX_HEALTH)
        {
            drawHealthFace.setFace(2);
        }
        else if (health > .2 * MAX_HEALTH)
        {
            drawHealthFace.setFace(3);
        }
        else
        {
            drawHealthFace.setFace(4);
        }

        // for drawing the health bar
        drawHealthBar.setPercent(((float)health / (float)MAX_HEALTH));
    }