Exemple #1
0
    void fall_sequence()
    {
        // Move Left
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            // Modify position
            transform.position += new Vector3(-1, 0, 0);

            // See if valid
            if (isValidGridPos())
            {
                // It's valid. Update Grid2d.
                updateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.position += new Vector3(1, 0, 0);
            }
        }

        // Move Right
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            // Modify position
            transform.position += new Vector3(1, 0, 0);

            // See if valid
            if (isValidGridPos())
            {
                // It's valid. Update Grid2d.
                updateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.position += new Vector3(-1, 0, 0);
            }
        }

        // Rotate
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            transform.Rotate(0, 0, -90);

            // See if valid
            if (isValidGridPos())
            {
                updateGrid();
            }
            else
            {
                transform.position += new Vector3(-1, 0, 0);
                if (isValidGridPos())
                {
                    updateGrid();
                }
                else
                {
                    transform.position += new Vector3(-1, 0, 0);
                    if (isValidGridPos())
                    {
                        updateGrid();
                    }
                    else
                    {
                        transform.position += new Vector3(3, 0, 0);
                        if (isValidGridPos())
                        {
                            updateGrid();
                        }
                        else
                        {
                            transform.position += new Vector3(1, 0, 0);
                            if (isValidGridPos())
                            {
                                updateGrid();
                            }
                            else
                            {
                                // It's not valid. revert.
                                transform.Rotate(0, 0, 90);
                                transform.position += new Vector3(-2, 0, 0);
                            }
                        }
                    }
                }
            }
        }
        // Move Downwards and Fall
        else if ((Input.GetKey(KeyCode.DownArrow) && Time.time - lastFall >= 0.1) ||
                 Time.time - lastFall >= fallTime)
        {
            // Modify position
            transform.position += new Vector3(0, -1, 0);

            // See if valid
            if (isValidGridPos())
            {
                // It's valid. Update Grid2d.
                updateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.position += new Vector3(0, 1, 0);

                audiosource.PlayOneShot(fallSE);
                Spawner2d.second_ban = false;

                // Clear filled horizontal lines
                Grid2d.deleteFullRows();

                // Spawn next Group
                FindObjectOfType <Spawner2d>().spawnNext();

                // 落ちるのが早くなるところ
                if (ScoreText.addFallBlocks() % fallThreshNum == 0)
                {
                    if (fallTime > underFallVel)
                    {
                        fallTime -= 0.1;
                    }

                    Debug.Log("fallTime ->" + fallTime.ToString());
                }

                // Disable script
                enabled = false;
            }

            lastFall = Time.time;
        }
        // Fall
        else if (Input.GetKeyUp(KeyCode.Space))
        {
            int score = 0;

            while (true)
            {
                transform.position += new Vector3(0, -1, 0);

                if (!isValidGridPos())
                {
                    // It's not valid. revert.
                    transform.position += new Vector3(0, 1, 0);
                    break;
                }
                score++;
            }
            updateGrid();

            audiosource.PlayOneShot(fallSE);
            Spawner2d.second_ban = false;

            //スコア加算
            ScoreText.addScore(score);

            // Clear filled horizontal lines
            Grid2d.deleteFullRows();

            // Spawn next Group
            FindObjectOfType <Spawner2d>().spawnNext();

            // 落ちるのが早くなるところ
            if (ScoreText.addFallBlocks() % fallThreshNum == 0)
            {
                if (fallTime > underFallVel)
                {
                    fallTime -= 0.1;
                }
                Debug.Log("fallTime ->" + fallTime.ToString());
            }

            // Disable script
            enabled = false;
        }
    }