示例#1
0
    public void moveTetrisBlock(int input, ref TetrisBlock activeBlock, Vector2 position)
    {
        switch (input)
        {
        case 0:
            //move left
            if (!checkLeftBoundCollision())
            {
                activeBlock.updateLocation(new Vector2(-1, 0));
            }

            if (checkInternalCollision())
            {
                activeBlock.updateLocation(new Vector2(1, 0));
            }

            break;

        case 1:
            //move right
            if (!checkRightBoundCollision())
            {
                activeBlock.updateLocation(new Vector2(1, 0));
            }

            if (checkInternalCollision())
            {
                activeBlock.updateLocation(new Vector2(-1, 0));
            }

            break;

        case 2:
            //move down
            while (true)
            {
                activeBlock.updateLocation(new Vector2(0, 1));

                if (checkFallCollision())
                {
                    activeBlock.updateLocation(new Vector2(0, -1));
                    break;
                }
            }
            break;

        case 3:
            //rotate right
            activeBlock.rotateRight();

            if (checkInGrid())
            {
                activeBlock.rotateRight();
            }
            activeBlock.rotateRight();
            activeBlock.rotateRight();

            if (checkInternalCollision())
            {
                activeBlock.rotateRight();
                activeBlock.rotateRight();
                activeBlock.rotateRight();
            }
            break;

        case 4:
            //rotate left
            activeBlock.rotateRight();
            activeBlock.rotateRight();
            activeBlock.rotateRight();

            if (checkInGrid())
            {
                activeBlock.rotateRight();
            }

            if (checkInternalCollision())
            {
                activeBlock.rotateRight();
            }

            break;

        case 1000:

            break;

        default:
            break;
        }

        if (!checkBlockOnBlockCollision())
        {
            activeBlock.updateLocation(new Vector2(0, 1));
        }
    }