Пример #1
0
    private void Update()
    {
        // Move Left
        if (Input.GetButtonDown("Left") && UIControl.canDrop == true)
        {
            // Modify position
            transform.position += new Vector3(-1, 0, 0);

            // See if valid
            if (IsValidGridPos())
            {
                // Its valid. Update grid.
                UpdateGrid();
            }
            else
            {
                // Its not valid. revert.
                transform.position += new Vector3(1, 0, 0);
            }
        }
        // Move Right
        else if (Input.GetButtonDown("Right") && UIControl.canDrop == true)
        {
            // Modify position
            transform.position += new Vector3(1, 0, 0);

            // See if valid
            if (IsValidGridPos())
            {
                // It's valid. Update grid.
                UpdateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.position += new Vector3(-1, 0, 0);
            }
        }
        // Rotate
        else if (Input.GetButtonDown("Rotate") && groupName.ToLower() != "o" && UIControl.canDrop == true)
        {
            transform.Rotate(0, 0, -90);

            // See if valid
            if (IsValidGridPos())
            {
                // It's valid. Update grid.
                UpdateGrid();
            }
            else
            {
                // It's not valid. revert.
                transform.Rotate(0, 0, 90);
            }
        }
        else if (Input.GetButtonDown("Fall") && UIControl.canDrop == true)
        {
            Scoring.score++;

            // Modify position
            transform.position += new Vector3(0, -1, 0);

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

                // Clear filled horizontal lines
                BoxGrid.DeleteFullRows();

                // Disable script
                enabled = false;

                // Spawn next Group
                FindObjectOfType <Spawner>().SpawnNext();
            }
            Scoring.UpdateUI();
        }
        // Move Downwards and Fall
        else if (UIControl.canDrop == true && Time.time - lastFall >= fallTick)
        {
            // Modify position
            transform.position += new Vector3(0, -1, 0);

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

                // Clear filled horizontal lines
                BoxGrid.DeleteFullRows();

                // Disable script
                enabled = false;

                // Spawn next Group
                FindObjectOfType <Spawner>().SpawnNext();
            }

            lastFall = Time.time;
        }
        // Move Downwards and Fall
        else if (Input.GetButton("Hard Drop") || hardDrop == true)
        {
            if (UIControl.canDrop == true)
            {
                // Modify position
                transform.position += new Vector3(0, -1, 0);
                Scoring.score++;

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

                    // Clear filled horizontal lines
                    BoxGrid.DeleteFullRows();

                    // Disable script
                    enabled = false;
                    Scoring.UpdateUI();

                    // Spawn next Group
                    FindObjectOfType <Spawner>().SpawnNext();
                }
            }
        }
    }
Пример #2
0
    public void UIInput(string control)
    {
        if (target != null)
        {
            // Move Left
            if (control == "Left" && canDrop == true)
            {
                // Modify position
                target.transform.position += new Vector3(-1, 0, 0);

                sfxSource.PlayOneShot(move);

                // See if valid
                if (target.IsValidGridPos())
                {
                    // Its valid. Update grid.
                    target.UpdateGrid();
                }
                else
                {
                    // Its not valid. revert.
                    target.transform.position += new Vector3(1, 0, 0);
                }
            }
            // Move Right
            else if (control == "Right" && canDrop == true)
            {
                // Modify position
                target.transform.position += new Vector3(1, 0, 0);

                sfxSource.PlayOneShot(move);

                // See if valid
                if (target.IsValidGridPos())
                {
                    // It's valid. Update grid.
                    target.UpdateGrid();
                }
                else
                {
                    // It's not valid. revert.
                    target.transform.position += new Vector3(-1, 0, 0);
                }
            }
            // Rotate
            else if (control == "Rotate" && target.groupName.ToLower() != "o" && canDrop == true)
            {
                sfxSource.PlayOneShot(rotate);

                target.transform.Rotate(0, 0, -90);

                // See if valid
                if (target.IsValidGridPos())
                {
                    // It's valid. Update grid.
                    target.UpdateGrid();
                }
                else
                {
                    // It's not valid. revert.
                    target.transform.Rotate(0, 0, 90);
                }
            }
            else if (control == "Soft Drop")
            {
                if (canDrop == true)
                {
                    Scoring.score++;

                    // Modify position
                    target.transform.position += new Vector3(0, -1, 0);
                    sfxSource.PlayOneShot(move);

                    // See if valid
                    if (target.IsValidGridPos())
                    {
                        // It's valid. Update grid.
                        target.UpdateGrid();
                    }
                    else
                    {
                        // It's not valid. revert.
                        target.transform.position += new Vector3(0, 1, 0);

                        // Clear filled horizontal lines
                        BoxGrid.DeleteFullRows();

                        // Disable script
                        target.enabled = false;

                        // Spawn next Group
                        FindObjectOfType <Spawner>().SpawnNext();
                    }
                    Scoring.UpdateUI();
                }
            }
            else if (control == "Hard Drop" && canDrop == true)
            {
                target.hardDrop = true;
            }
        }
    }