/** * Holds a background image up for the specified time. * Loads the correct level */ void Update() { timePassed -= Time.deltaTime; // decrement the time passed variable by how much time since the last update call if (timePassed < 0) // check if the maximum time has passed { // if it has load the correct si level if (level.getLevel() == 0) { Application.LoadLevel("SmallIntestineTutorial"); } else if (level.getLevel() % 2 == 0) { Application.LoadLevel("SmallIntestineEven"); } else { Application.LoadLevel("SmallIntestineOdd"); } /* * if (level.getLevel () == 0) { * Application.LoadLevel ("SmallIntestineTutorial"); * } else if (level.getLevel () == 1) { * Application.LoadLevel("SmallIntestineOdd"); * } else if (level.getLevel () == 4) { * Application.LoadLevel("SmallIntestineOdd"); * } */ } }
/** * for checking if the new score earned is the highest ever and if it is save it */ void saveHighScore() { // load the previously saved highest score prevHighScore = PlayerPrefs.GetInt("SI" + (level.getLevel() - 1)); // check if the new score is higher than the previous high score if (prevHighScore < numStars) { // if it is the high score save it prevHighScore = numStars; PlayerPrefs.SetInt("SI" + (level.getLevel() - 1), numStars); } }
/** * Handles drawing of game over popup menu */ void OnGUI() { float scale = 234f / 489f; float buttonWidth = Screen.width * 0.1591796875f; // draw the game over popup box in the middle of the screen GUI.DrawTexture(new Rect(Screen.width * 0.26953125f, Screen.height * 0.18359375f, Screen.width * 0.4609375f, Screen.height * 0.6328125f), gameOverPopup); // draw restart button if (GUI.Button(new Rect(Screen.width * 0.3251953125f, Screen.height * 0.66666666666f, buttonWidth, buttonWidth * scale), "", restart)) { // if restart is pressed Time.timeScale = 1; // unpause the game GameObject chooseBackground = GameObject.Find("ChooseBackground"); // find the background chooser SmallIntestineLoadLevelCounter level = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>(); // restart from the correct level if (level.getLevel() % 2 == 0) { Application.LoadLevel("SmallIntestineEven"); } else { Application.LoadLevel("SmallIntestineOdd"); } } // draw main menu button if (GUI.Button(new Rect(Screen.width * 0.5166015625f, Screen.height * 0.66666666666f, buttonWidth, buttonWidth * scale), "", mainMenu)) { // if main menu is selected Time.timeScale = 1; // unpause the game GameObject chooseBackground = GameObject.Find("ChooseBackground"); // find the background chooser SmallIntestineLoadLevelCounter level = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>(); level.resetLevel(); // reset the small intestine current level to 1 for next time Application.LoadLevel("MainMenu"); // load the main menu } }
/** * Handles drawing of game over popup menu */ void OnGUI() { // draw the game over popup box in the middle of the screen GUI.DrawTexture(new Rect(Screen.width * 0.3193359375f, Screen.height * 0.28515625f, Screen.width * 0.3603515625f, Screen.height * 0.248697917f), gameOverPopup); // draw restart button if (GUI.Button(new Rect(Screen.width * 0.41015625f, Screen.height * 0.41927083f, Screen.width * 0.0654296875f, Screen.height * 0.06640625f), "", restart)) { // if restart is pressed Time.timeScale = 1; // unpause the game GameObject chooseBackground = GameObject.Find("ChooseBackground"); // find the background chooser SmallIntestineLoadLevelCounter level = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>(); // restart from the correct level if (level.getLevel() % 2 == 0) { Application.LoadLevel("SmallIntestineEven"); } else { Application.LoadLevel("SmallIntestineOdd"); } } // draw main menu button if (GUI.Button(new Rect(Screen.width * 0.53125f, Screen.height * 0.41927083f, Screen.width * 0.0654296875f, Screen.height * 0.06640625f), "", mainMenu)) { // if main menu is selected Time.timeScale = 1; // unpause the game GameObject chooseBackground = GameObject.Find("ChooseBackground"); // find the background chooser SmallIntestineLoadLevelCounter level = chooseBackground.GetComponent <SmallIntestineLoadLevelCounter>(); level.resetLevel(); // reset the small intestine current level to 1 for next time Application.LoadLevel("MainMenu"); // load the main menu } }
/** * 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 } } }
/** * Chooses and draws the correct loading screen image */ void OnGUI() { counter = GameObject.Find("ChooseBackground"); // find a reference to the background chooser level = counter.GetComponent <SmallIntestineLoadLevelCounter> (); // to get a reference to the script on the background chooser // draw the loading screen texture across the entire screen GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), backgrounds [Mathf.Clamp(level.getLevel(), 0, level.getMaxLevels())]); }
public bool end = false; //!< to remember if we are done reading new waves from a script /** * Use this for initialization * Check if game was loaded properly. If not reload. * Start spawning waves. */ void Start() { level = null; // initially set the reference to null GameObject counter = GameObject.Find("ChooseBackground"); // try to find an instance of the background chooser if (counter != null) // if the counter is not null we can continue as normal with initialization { // if the counter was there we can just get the level level = counter.GetComponent <SmallIntestineLoadLevelCounter> (); } else // if we start the level from the game itself just start at level 0, 1, or 2 appropriately { // this part should only happen if we start the game from the wrong scene in the unity editor // if the counter wasn't there reload properly // this will reload the entire game from the level it was supposed to be loaded from if (Application.loadedLevelName == "SmallIntestineTutorial") { // if we load directly from the tutorial scene, then reload the si game from level 0 PlayerPrefs.SetInt("DesiredSILevel", 0); PlayerPrefs.Save(); Application.LoadLevel("LoadLevelSmallIntestine"); } else if (Application.loadedLevelName == "SmallIntestineOdd") { // if we load directly from the si odd scene, then reload the si game from level 1 PlayerPrefs.SetInt("DesiredSILevel", 1); PlayerPrefs.Save(); Application.LoadLevel("LoadLevelSmallIntestine"); } else if (Application.loadedLevelName == "SmallIntestineEven") { // if we load directly from the si even scene, then reload the game from level 2 PlayerPrefs.SetInt("DesiredSILevel", 2); PlayerPrefs.Save(); Application.LoadLevel("LoadLevelSmallIntestine");; } } // load in the script info if (counter != null) // guard check to prevent this code from executing before the game is reloaded { // start loading in the script loadScript = new LoadScript(); // create a new script loader //if (!level.getTutorial ()) { //if not tutorial waves = loadScript.loadIntestineLevel(level.getLevel(), level.isTutorial(), level.getTutorialNum()); // get the waves for the correct script currentWave = 0; // set the current wave index to 0 waveDelay = waves[0].startDelay; // get the start delay from the first parsed wave waveTime = waves[0].runTime; // get the run time from the first parsed wave SpawnInterval = waves[0].nutrientSpawnInterval; // get the nutrient spawn interval from the first parsed wave speed = waves[0].nutrientSpeed; // get the nutrient speed from the first parsed wave availableColors = waves[0].colors; // get the colors for the first parsed wave minNutrients = waves[0].minBlobs; // get the min blobs for the first parsed wave maxNutrients = waves[0].maxBlobs; // get the max blobs for the first parsed wave m_TimeSinceLastSpawn = 0f; // start the timesincelastspawn variable to 0 } // we don't use debug config in the tutorial level so check that we aren't in the tutorial level before // we look for a reference to the debugger to get the debug script if (Application.loadedLevelName != "SmallIntestineTutorial") { debugConfig = ((GameObject)GameObject.Find("Debug Config")).GetComponent <DebugConfig>(); } }