public IEnumerator Play() { phoneShake.shakeCount = 0; // Reset phone shake count so they can reshake blocks. //Get current highscore (done so it isn't stored on replays of same level) GameManager.manager.level[GameManager.manager.currentLevel].highestPoints = PlayerPrefs.GetInt("level" + GameManager.manager.currentLevel + "highestPoints"); GameManager.manager.newHighScore = false; GameManager.manager.newLowestShots = false; GameManager.manager.ballsActive = false; ableToShoot = false; //Get number of balls for this level ballControl.CalculateNumberOfBalls(); //set current shot to 0 GameManager.manager.level[GameManager.manager.currentLevel].shotPoints = 0; //show highest points highScoreText.text = ("Highest: " + GameManager.manager.level[GameManager.manager.currentLevel].highestPoints); //show lowest shots taken lowestShotsTakenText.text = ("Lowest: " + PlayerPrefs.GetInt("level" + GameManager.manager.currentLevel + "lowestShotsTaken"));// GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken); //show the level number levelNumberText.text = "Level " + GameManager.manager.currentLevel.ToString(); //show player coins playerCoinsText.text = GameManager.manager.playerCoins.ToString(); //Show the number of balls to play this shot numberOfBallsText.text = GameManager.manager.maxNumberOfBalls + " Balls This Shot"; //used for the reward line rewardLine.fillAmount = 0; oldFillAmount = 0; //Check if firstRun to stop getting highscores when highest score == 0 (lowestshots checked at end of level) if (GameManager.manager.level[GameManager.manager.currentLevel].highestPoints == 0) { GameManager.manager.firstRun = true; } else { GameManager.manager.firstRun = false; } //Set the number of balls according to current level; //GameManager.manager.maxNumberOfBalls = GameManager.manager.baseNumberOfBalls + (int)(Mathf.Round((GameManager.manager.currentLevel / 5))); //Initialise block colours (if not a bonus level) if bonus level, say so :) if (GameManager.manager.currentLevel % GameManager.manager.bonusLevel != 0) { BlockColour(); } else { //StartCoroutine(GameManager.manager.Message("Bonus Level" + "\r\n" + "Double Balls!"+"\r\n"+"Double Reward!", new Vector2(0, 0), 8, 2.5f, Color.white)); StartCoroutine(GameManager.manager.Message("Double Balls!" + "\r\n" + "Double Reward!", new Vector2(0, 0), 8, 2.5f, Color.white)); BlockColour(); // remove if doing the bonus levels with their own colour } // suggest a powerup if they have retried several times if ((GameManager.manager.retries % 5 == 0) && (GameManager.manager.retries != 0)) { needAPowerUp.TimeForPowerUp(); } //Play until level end while ((GameManager.manager.actualNumberOfBlocks > 0) && (!levelFailed)) { //launch balls LaunchBalls(); // Store current state of play here for reversal if needed //update the level text UpdateLevelText(); //update the reward line UpdateRewardLine(); // Check if all balls have finished on screen and move blocks down BallsFinished(); //move blocks down //check if bottom reached and show fail panel....give chance to continue StartCoroutine(HasBottomBeenReached()); //if bottom reached, wait until continue selected, or they retry or go home while (bottomReached == true) { yield return(null); } yield return(null); //Double check all blocks are gone (sometimes there are blocks left in frantic levels) GameObject[] block = GameObject.FindGameObjectsWithTag("block"); GameManager.manager.actualNumberOfBlocks = block.Length; } //reset time to default Time.timeScale = 1; //StartCoroutine(ShotPanelHide()); //Mark level as done and available in future if (GameManager.manager.actualNumberOfBlocks <= 0) { // Remove any errant balls StartCoroutine(ForceBallsToFinish()); yield return(new WaitForSecondsRealtime(0.5f)); //if level completed check if lowestshotstaken needs to be updated //update lowest shots taken if ((shotsTaken < GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken) || (GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken == 0)) { //Avoid giving new record on first run if (GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken != 0) { //GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken = shotsTaken; GameManager.manager.newLowestShots = true; } GameManager.manager.level[GameManager.manager.currentLevel].lowestShotsTaken = shotsTaken; lowestShotsTakenText.text = ("Lowest: " + shotsTaken); } //set the stars for the level These are the stored stars! if (rewardLine.fillAmount == 1) { GameManager.manager.level[GameManager.manager.currentLevel].stars = 3; } else if ((rewardLine.fillAmount >= 0.75f) && (GameManager.manager.level[GameManager.manager.currentLevel].stars < 3)) { GameManager.manager.level[GameManager.manager.currentLevel].stars = 2; } else if ((rewardLine.fillAmount < 0.75f) && (GameManager.manager.level[GameManager.manager.currentLevel].stars < 2)) { GameManager.manager.level[GameManager.manager.currentLevel].stars = 1; } if (rewardLine.fillAmount == 1) // These are used to calculate coins -- if already got 3 stars, but now got 2, pay 2. { GameManager.manager.currentLevelStars = 3; } else if (rewardLine.fillAmount >= 0.75f) { GameManager.manager.currentLevelStars = 2; } else { GameManager.manager.currentLevelStars = 1; } //update complete level details GameManager.manager.LevelComplete(); StartCoroutine(ShotPanelHide()); //Disable the bottom panel bottomPanel.SetActive(false); //show the pass panel passPanel.SetActive(true); //AudioSource.PlayClipAtPoint(GameManager.manager.levelPassSound, gameObject.transform.localPosition); //USE TO prevent shooting bottomReached = true; } else // level failed { Time.timeScale = 1; // Remove any errant balls //StartCoroutine(ForceBallsToFinish()); //slight delay /* * for (int wait = 0; wait < 130; wait++) * { * yield return null; * } */ AudioSource.PlayClipAtPoint(GameManager.manager.levelFailSound, gameObject.transform.localPosition); yield return(new WaitForSecondsRealtime(0.5f)); failPanel.SetActive(true); StartCoroutine(ShotPanelHide()); } GameManager.manager.ballsActive = false; }