Exemplo n.º 1
0
    public bool CheckForInsideBorder(Transform figure)
    {
        foreach (Transform child in figure)
        {
            Vector2 positionChild = VectorsMath.RoundVector2(child.position);

            if (positionChild.x < 0 || positionChild.x >= _width)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 2
0
    public void MoveFigureHorizontally(Transform figure, int direction)
    {
        figure.position += new Vector3(direction, 0, 0);

        if (figure.position.x >= _grid.GetWidth() || figure.position.x < 0)
        {
            //Смещаем родителя, а всё что осталось за границами возвращаем обратно
            figure.position += new Vector3(-direction * _grid.GetWidth(), 0, 0);

            foreach (Transform child in figure)
            {
                Vector2 positionChild = VectorsMath.RoundVector2(child.position);

                if (positionChild.x >= _grid.GetWidth() || positionChild.x < 0)
                {
                    child.position += new Vector3(direction * _grid.GetWidth(), 0, 0);
                }
            }
        }
        else
        {
            //смещаем дочерние объекты
            foreach (Transform child in figure)
            {
                Vector2 positionChild = VectorsMath.RoundVector2(child.position);

                if (positionChild.x >= _grid.GetWidth() || positionChild.x < 0)
                {
                    child.position += new Vector3(-direction * _grid.GetWidth(), 0, 0);
                }
            }
        }
        if (_grid.CheckForCollisionWithFigureOrFloor(figure))
        {
            _grid.UpdateGrid(figure);
        }
        else
        {
            MoveFigureHorizontally(figure, -direction);
        }
    }
Exemplo n.º 3
0
    public bool CheckForCollisionWithFigureOrFloor(Transform figure)
    {
        foreach (Transform child in figure)
        {
            Vector2 positionChild = VectorsMath.RoundVector2(child.position);

            if (positionChild.y < 0)
            {
                return(false);
            }

            Transform arrayPosition = _arrayOfGridCells[(int)positionChild.x, (int)positionChild.y];

            if (arrayPosition != null &&
                arrayPosition.parent != figure)
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 4
0
    public void UpdateGrid(Transform figure)
    {
        for (int i = 0; i < _width; i++)
        {
            for (int j = 0; j < _height; j++)
            {
                if (_arrayOfGridCells[i, j] != null &&
                    _arrayOfGridCells[i, j].parent == figure)
                {
                    _arrayOfGridCells[i, j] = null;
                }
            }
        }

        foreach (Transform child in figure)
        {
            Vector2 positionChild = VectorsMath.RoundVector2(child.position);
            _arrayOfGridCells[(int)positionChild.x, (int)positionChild.y] = child;
        }

        /*
         * string mes = "";
         * for (int i = 0; i < _width; i++)
         * {
         *  for (int j = 0; j < _height; j++)
         *  {
         *      if (_arrayOfGridCells[i, j] == null)
         *          mes += ".";
         *      else
         *          mes += "0";
         *  }
         *  Debug.Log(mes);
         *  mes = "";
         * }
         */
    }