Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (nextY < CameraExtensions.GetEdges(Camera.main)[1])
     {
         GenerateRows(1);
     }
 }
Beispiel #2
0
    void GenerateRows(int count)
    {
        // left and right edges are constant in our case so maybe not necessary to call this every loop?
        // not too taxing so can be left for now
        List <float> cameraEdges = CameraExtensions.GetEdges(Camera.main);

        for (int c = 0; c < count; c++)
        {
            nextY += intervalY;
            List <GameObject> row = new List <GameObject>();
            for (int x = 0; x < cols; x++)
            {
                float xStep = (ScreenDims.x / cols);
                float px    = (x * xStep) - (HalfDims.x) + .6f;
                row.Add(Instantiate(PlatformPrefab, new Vector3(px, nextY, 0), Quaternion.identity));
            }

            int rand = Random.Range(cols / 2, cols);
            for (int i = 0; i < rand; i++) // remove between 1 and col minus 1 platforms per row
            {
                int index = Random.Range(0, row.Count);
                Destroy(row[index]);
                row.RemoveAt(index);
            }

            if (Random.value < CoinChance && GenerateCoins)
            {
                // spawn coin based on random chance per row generated
                Instantiate(CoinPrefab, new Vector3(Random.Range(cameraEdges[0], cameraEdges[2]), nextY + 0.5f, 0), Quaternion.identity);
            }

            row.Clear();
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (transform.position.y + 1 < CameraExtensions.GetEdges(Camera.main)[3])
     {
         Destroy(gameObject);
     }
 }
 // Update is called once per frame
 void Update()
 {
     // remove from game if off screen
     if (transform.position.y + 1 < CameraExtensions.GetEdges(Camera.main)[3])
     {
         Destroy(gameObject);
     }
 }
Beispiel #5
0
 public void Update()
 {
     if (Backgrounds[0].transform.position.y + BackgroundHeight < CameraExtensions.GetEdges(Camera.main)[3])
     {
         Destroy(Backgrounds[0]);
         Backgrounds.RemoveAt(0);
         NextBackground();
     }
 }
    // Update is called once per frame
    void Update()
    {
        switch (CurrentState)
        {
        case STATE.UNPAUSED:
            // timer decrements while playing
            TimeLeft         -= Time.deltaTime;
            _TimeSlider.value = TimeLeft / MAXTIME;

            // Gameover when timer below 0
            if (TimeLeft <= 0)
            {
                SetGamestate(STATE.GAMEOVER);
            }

            // player loses if they fall off the bottom of screen
            KillY = CameraExtensions.GetEdges(Camera.main)[3] - 0.1f;
            if (_Plr.transform.position.y < KillY)
            {
                SetGamestate(STATE.GAMEOVER);
            }
            break;

        case STATE.PREGAME:
            // starting the game
            if (Input.GetKeyDown(KeyCode.Space))
            {
                _ScoreUI.enabled   = true;
                _PregameUI.enabled = false;
                SetGamestate(STATE.UNPAUSED);
            }
            break;

        case STATE.QUESTION:
            // similar deal with above code
            QuestionTimeLeft     -= Time.deltaTime;
            _QuestionSlider.value = QuestionTimeLeft / QUESTIONMAXTIME;

            // submit wrong answer when timer below 0
            if (QuestionTimeLeft <= 0)
            {
                TimeLeft -= COINTIME;
                QuestionAnswer(-1);
            }
            break;

        case STATE.ANSWER:
            // similar deal with above code
            AnswerTimeLeft -= Time.deltaTime;

            // transition to gameplay again when timer below 0
            if (AnswerTimeLeft <= 0)
            {
                foreach (GameObject b in _QButtons)
                {
                    // reset colors
                    b.GetComponent <Image>().color = new Color(255, 255, 255, 255);
                }

                SetGamestate(STATE.UNPAUSED);
            }
            break;

        default:
            break;
        }
    }