예제 #1
0
    // Faz a peça descer rapido até seu limite
    public void Abater()
    {
        timer += Time.deltaTime;
        while (posicaoValida())
        {
            transform.position += new Vector3(0, -1, 0);
        }
        if (!posicaoValida())
        {
            transform.position += new Vector3(0, 1, 0);

            gManager.atualizaGrade(this);

            gManager.apagaLinha();

            if (gManager.acimaGrade(this))
            {
                gManager.gameOver();
            }

            PlayLandAudio();

            gManager.score += 10;

            gManager.pontoDificuldade += 10;

            enabled = false;

            gSpawner.proximaPeca();
        }
    }
예제 #2
0
    void Update()

    {
        if (!gManager.pause)
        {
            if (gManager.pontoDificuldade > 1000)
            {
                gManager.pontoDificuldade -= 1000;

                gManager.dificuldade += .5f; //Quanto maior mais dificil !
            }


            if ((Input.GetKeyUp(KeyCode.RightArrow)) || (Input.GetKeyUp(KeyCode.LeftArrow)) || (Input.GetKeyUp(KeyCode.DownArrow)))
            {
                timer = velocidade;
            }



            if (Input.GetKey(KeyCode.RightArrow))
            {
                timer += Time.deltaTime;

                if (timer > velocidade)
                {
                    transform.position += new Vector3(1, 0, 0);
                    timer = 0;
                }

                if (posicaoValida())
                {
                    gManager.atualizaGrade(this);
                }
                else
                {
                    transform.position += new Vector3(-1, 0, 0);
                }
            }
            //---------------------------------------------------------------------
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                timer += Time.deltaTime;
                if (timer > velocidade)
                {
                    transform.position += new Vector3(-1, 0, 0);
                    timer = 0;
                }
                if (posicaoValida())
                {
                    gManager.atualizaGrade(this);
                }
                else
                {
                    transform.position += new Vector3(1, 0, 0);
                }
            }

            //---------------------------------------------------------------------

            if (Input.GetKey(KeyCode.DownArrow))//|| Time.time-queda >= 1 )
            {
                timer += Time.deltaTime;

                if (timer > velocidade)
                {
                    transform.position += new Vector3(0, -1, 0);
                    timer = 0;
                }
                if (posicaoValida())
                {
                    gManager.atualizaGrade(this);
                }
                else
                {
                    transform.position += new Vector3(0, 1, 0);
                    gManager.apagaLinha();

                    if (gManager.acimaGrade(this))
                    {
                        gManager.gameOver();
                    }

                    //PODE REMOVER SCORE 10
                    gManager.score            += 10;
                    gManager.pontoDificuldade += 10;
                    enabled = false;
                    gSpawner.proximaPeca();
                }

                // queda = Time.time;
            }

            //queda

            if (Time.time - queda >= (1 / gManager.dificuldade) && !Input.GetKey(KeyCode.DownArrow))
            {
                transform.position += new Vector3(0, -1, 0);
                if (posicaoValida())
                {
                    gManager.atualizaGrade(this);
                }
                else
                {
                    transform.position += new Vector3(0, 1, 0);
                    gManager.apagaLinha();

                    if (gManager.acimaGrade(this))
                    {
                        gManager.gameOver();
                    }

                    //PODE REMOVER SCORE 10
                    //gManager.score += 10;
                    gManager.pontoDificuldade += 10;
                    enabled = false;
                    gSpawner.proximaPeca();
                }
                queda = Time.time;
            }
            //---------------------------------------------------------------------
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (podeRodar)
                {
                    if (!roda360)
                    {
                        if (transform.rotation.z < 0)
                        {
                            transform.Rotate(0, 0, 90);

                            if (posicaoValida())
                            {
                                gManager.atualizaGrade(this);
                            }
                            else
                            {
                                transform.Rotate(0, 0, -90);
                            }
                        }
                        else
                        {
                            transform.Rotate(0, 0, -90);

                            if (posicaoValida())
                            {
                                gManager.atualizaGrade(this);
                            }
                            else
                            {
                                transform.Rotate(0, 0, 90);
                            }
                        }
                    }
                    else
                    {
                        transform.Rotate(0, 0, -90);

                        if (posicaoValida())
                        {
                            gManager.atualizaGrade(this);
                        }
                        else
                        {
                            transform.Rotate(0, 0, 90);
                        }
                    }
                }
            }
        }
    }