Exemple #1
0
    public void MoveLeft()
    {
        if (mHandlerControlEnv == null)
        {
            mHandlerControlEnv = handleObj.transform.parent.GetComponent <ControlEnvironment>();
        }

        // check if the object can go left
        mHandleObjPropertyHandler.canGoLeft = true;
        for (int i = 0; i < AllObjs.Count && mHandleObjPropertyHandler.canGoLeft; i++)
        {
            Vector3 p = ((GameObject)AllObjs[i]).transform.position;

            Vector2Int id = CreateObject.GetIndex(p);

            if (id.x <= 0)
            {
                mHandleObjPropertyHandler.canGoLeft = false;
                break;
            }
            if (mHandlerControlEnv.tetrisMap[id.y][id.x - 1] == 1)
            {
                mHandleObjPropertyHandler.canGoLeft = false;
                break;
            }
        }

        if (mHandleObjPropertyHandler.canGoLeft)
        {
            handleObj.transform.position += new Vector3(-1, 0, 0);
        }
        CheckForBoundaries();
    }
Exemple #2
0
    public bool MoveDown()
    {
        if (mHandlerControlEnv == null)
        {
            mHandlerControlEnv = handleObj.transform.parent.GetComponent <ControlEnvironment>();
        }

        // check if the object can go down
        mHandleObjPropertyHandler.canGoDown = true;
        for (int i = 0; i < AllObjs.Count && mHandleObjPropertyHandler.canGoDown; i++)
        {
            Vector3 p = ((GameObject)AllObjs[i]).transform.position;

            Vector2Int id = CreateObject.GetIndex(p);

            if (id.y <= 0)
            {
                mHandleObjPropertyHandler.canGoDown = false;
                break;
            }
            if (mHandlerControlEnv.tetrisMap[id.y - 1][id.x] == 1)
            {
                mHandleObjPropertyHandler.canGoDown = false;
                break;
            }
        }

        if (mHandleObjPropertyHandler.canGoDown)
        {
            handleObj.transform.position += new Vector3(0, -1, 0);
            return(true);
        }
        return(false);
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (this.tag == "MovingBlock")
        {
            if (collision.transform.tag == "Block")
            {
                ControlEnvironment tmp_handler = collision.transform.parent.GetComponent <ControlEnvironment>();
                Vector3            p           = this.transform.position;

                Vector2Int id = CreateObject.GetIndex(p);

                if (id.y - 1 >= 0 && tmp_handler.tetrisMap[id.y - 1][id.x] == 1)
                {
                    handleObj.GetComponent <BlockObjProperty>().canGoDown = false;
                }
            }
            if (collision.transform.tag == "Ground")
            {
                handleObj.GetComponent <BlockObjProperty>().canGoDown = false;
            }
            if (collision.transform.tag == "LeftWall")
            {
                handleObj.GetComponent <BlockObjProperty>().canGoLeft = false;
            }
            if (collision.transform.tag == "RightWall")
            {
                handleObj.GetComponent <BlockObjProperty>().canGoRight = false;
            }
        }
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if (mHandlerControlEnv == null)
        {
            mHandlerControlEnv = handleObj.transform.parent.GetComponent <ControlEnvironment>();
        }
        if (mHandleObjPropertyHandler == null && handleObj != null)
        {
            mHandleObjPropertyHandler = handleObj.GetComponent <BlockObjProperty>();
        }

        if (flagCreateOne)
        {
            MakeObject();
        }

        CheckForBoundaries();
    }
Exemple #5
0
    public void Rotate()
    {
        if (mHandlerControlEnv == null)
        {
            mHandlerControlEnv = handleObj.transform.parent.GetComponent <ControlEnvironment>();
        }

        Vector3 old_euler = handleObj.transform.rotation.eulerAngles;
        Vector3 new_euler = old_euler + new Vector3(0, 0, 90);

        handleObj.transform.rotation = Quaternion.Euler(new_euler);

        // check if the object can rotate
        bool flag_colide = false;

        for (int i = 0; i < AllObjs.Count && !flag_colide; i++)
        {
            Vector3 p = ((GameObject)AllObjs[i]).transform.position;

            Vector2Int id = CreateObject.GetIndex(p);

            if (id.x >= 0 && id.x < mHandlerControlEnv.tetrisMap[0].Length && id.y >= 0 && id.y < mHandlerControlEnv.tetrisMap.Length)
            {
                if (mHandlerControlEnv.tetrisMap[id.y][id.x] == 1)
                {
                    flag_colide = true;
                    break;
                }
            }
            else
            {
                flag_colide = true;
                break;
            }
        }

        // do not rotate if it is not possible
        if (flag_colide)
        {
            handleObj.transform.rotation = Quaternion.Euler(old_euler);
        }
        CheckForBoundaries();
    }