Example #1
0
    public void MoveBlock(InputController.SwipeType type, Vector2 cellIndex)
    {
        if (type == InputController.SwipeType.LEFT)
        {
            if (cellIndex.y - 1 >= 0)
            {
                if (cells[(int)cellIndex.x, (int)cellIndex.y - 1].GetComponent <Cell>().state == Cell.State.NotAssigned)
                {
                    blocks[(int)cellIndex.x, (int)cellIndex.y].GetComponent <Block>().ChangePosition(cells[(int)cellIndex.x, (int)cellIndex.y - 1].transform.position, new Vector2(cellIndex.x, cellIndex.y - 1));
                    blocks[(int)cellIndex.x, (int)cellIndex.y - 1] = blocks[(int)cellIndex.x, (int)cellIndex.y];

                    cells[(int)cellIndex.x, (int)cellIndex.y].GetComponent <Cell>().state     = Cell.State.NotAssigned;
                    cells[(int)cellIndex.x, (int)cellIndex.y - 1].GetComponent <Cell>().state = Cell.State.Assigned;

                    if (cells[(int)cellIndex.x + 1, (int)cellIndex.y - 1].GetComponent <Cell>().GetState == Cell.State.Assigned && blocks[(int)cellIndex.x + 1, (int)cellIndex.y - 1].GetComponent <Block>().state == Block.State.Fallen)
                    {
                        blocks[(int)cellIndex.x, (int)cellIndex.y - 1].GetComponent <Block>().state = Block.State.Fallen;
                        blocks[(int)cellIndex.x, (int)cellIndex.y - 1].GetComponent <Block>().UnSubscribeInputController();
                        blocks[(int)cellIndex.x, (int)cellIndex.y - 1].GetComponent <Block>().CheckCollision();
                    }
                }
            }
        }

        if (type == InputController.SwipeType.RIGHT)
        {
            if (cellIndex.y + 1 < columns)
            {
                if (cells[(int)cellIndex.x, (int)cellIndex.y + 1].GetComponent <Cell>().state == Cell.State.NotAssigned)
                {
                    blocks[(int)cellIndex.x, (int)cellIndex.y].GetComponent <Block>().ChangePosition(cells[(int)cellIndex.x, (int)cellIndex.y + 1].transform.position, new Vector2(cellIndex.x, cellIndex.y + 1));
                    blocks[(int)cellIndex.x, (int)cellIndex.y + 1] = blocks[(int)cellIndex.x, (int)cellIndex.y];

                    cells[(int)cellIndex.x, (int)cellIndex.y].GetComponent <Cell>().state     = Cell.State.NotAssigned;
                    cells[(int)cellIndex.x, (int)cellIndex.y + 1].GetComponent <Cell>().state = Cell.State.Assigned;

                    if (cells[(int)cellIndex.x + 1, (int)cellIndex.y + 1].GetComponent <Cell>().GetState == Cell.State.Assigned && blocks[(int)cellIndex.x + 1, (int)cellIndex.y + 1].GetComponent <Block>().state == Block.State.Fallen)
                    {
                        blocks[(int)cellIndex.x, (int)cellIndex.y + 1].GetComponent <Block>().state = Block.State.Fallen;
                        blocks[(int)cellIndex.x, (int)cellIndex.y + 1].GetComponent <Block>().UnSubscribeInputController();
                        blocks[(int)cellIndex.x, (int)cellIndex.y + 1].GetComponent <Block>().CheckCollision();
                    }
                }
            }
        }

        if (type == InputController.SwipeType.DOWN)
        {
            //GameObject.Find("GameManager").GetComponent<GameManager>().iterationLength = 0.1f;
            Time.timeScale = 10;
            Debug.Log("DOWN SWIPE EVENT!");
        }

        if (cells[(int)cellIndex.x + 1, (int)cellIndex.y].GetComponent <Cell>().GetState == Cell.State.Assigned &&
            blocks[(int)cellIndex.x + 1, (int)cellIndex.y].GetComponent <Block>().state == Block.State.Fallen)
        {
            blocks[(int)cellIndex.x + 1, (int)cellIndex.y].GetComponent <Block>().UnSubscribeInputController();
        }
    }
Example #2
0
 private void CheckSwipe(InputController.SwipeType type)
 {
     map.MoveBlock(type, cellIndex);
 }