Example #1
0
    void Update()
    {
        wind w = this.windController.GetComponent <wind>();

        // Note -90 compensation cos north is along 2D Y axis
        rot  = (-90 + this.transform.eulerAngles.y - north) * Mathf.Deg2Rad;
        rotW = (-90 + w.getAngle() - north) * Mathf.Deg2Rad;

        // Bubble position
        x = radius * Mathf.Cos(rot);
        y = radius * Mathf.Sin(rot);

        xW = radius * Mathf.Cos(rotW);
        yW = radius * Mathf.Sin(rotW);
    }
    // Once per physics check
    void FixedUpdate()
    {
        waveClock -= Time.deltaTime;

        if (heightFlag)
        {
            heightClock += Time.deltaTime;
        }
        if (!heightFlag)
        {
            heightClock = 0;
        }
        int cHeight = (int)((currentHeight / 0.75f) + 0.5);

        if (!waveOn)                                                            //if not currently in a wave / in build phase
        {
            //output.text = "Next Wave In: " + (int)waveClock;
            this.waveStartText.text = "WAVE STARTS IN " + (int)waveClock;

            if (waveClock <= 0 && !gameOver)                                                    //when build phase over, start wave
            {
                removeDebris();
                debrisThrown = 0;
                currentWave += 1;
                goalHeight   = (int)((currentWave * 2) * waveMultiplier);
                removeDebris();
                waveOn = true;
                windObj.beginWave(windObj.getMaxWSpeed() * waveMultiplier);
                waveClock = windTime;
            }
        }

        if (waveOn)                                                             //whilst in wave
        {
            //output.text = "Remaining Time: " + (int)waveClock;
            this.waveStartText.text = "WAVE ENDS IN " + (int)waveClock;
            float throwChance = Random.Range(0, 10000);
            if (throwChance <= 200 * waveMultiplier)
            {
                int angle = windObj.getAngle();
                debrisObj.throwDebris(angle);
                debrisThrown += 1;
            }
            //check if reached goal height
            if (cHeight >= goalHeight && waveClock <= windTime - 10)
            {
                endWave();
            }

            if (waveClock <= 0)
            {
                endWave();
                if (!testMode)
                {
                    gameOver = true;
                }
                //out of time before reaching goal height = gameOver
            }
        }
        checkGoalHeight();
        //output.text += " Wave: " + currentWave + "  Goal Height: " + goalHeight + "  SCORE:  " + score + "  CurrentHeight: " + cHeight;
        this.heightText.text = "HEIGHT - " + cHeight + " - " + goalHeight;
        this.scoreText.text  = "SCORE - " + score;
        this.waveText.text   = "WAVE - " + currentWave;

        if (gameOver)
        {
            PlayerPrefs.SetInt("score", score);
            PlayerPrefs.SetInt("wave", currentWave);
            Application.LoadLevel("endScene");
        }
    }