Beispiel #1
0
        public void GenerateBoard(Cell[,] boardCells)
        {
            _sizeX       = boardCells.GetLength(0);
            _sizeY       = boardCells.GetLength(1);
            _visualCells = new VisualCell[_sizeX, _sizeY];

            for (int x = 0; x < _sizeX; x++)
            {
                for (int y = 0; y < _sizeY; y++)
                {
                    //Create Cell
                    VisualCell cell = Instantiate(_cellPref, transform);
                    _visualCells[x, y] = cell;
                    cell.Init(boardCells[x, y]);
                    var cellTransform = cell.transform;
                    cellTransform.position = new Vector3(x, y, 0);

                    VisualBlock block = Instantiate(_blockPref, cellTransform);
                    block.Init(boardCells[x, y].Block);

                    cell.SetBlock(block, false);
                }
            }

            //Center the level map on the game screen
            transform.localPosition = new Vector2(-(_sizeX - 1) / 2.0f, -(_sizeY - 1) / 2.0f);

            BlockPlayersInput(false);
            Debug.Log($"Visual map was generated, size{_sizeX}x{_sizeY}");
        }
Beispiel #2
0
        public void SetNewBlock(Vector2Int boardPos, Block block)
        {
            var         visualCell  = GetVisualCell(boardPos);
            VisualBlock visualBlock = Instantiate(_blockPref, visualCell.transform);

            visualBlock.Init(block);
            visualCell.SetBlock(visualBlock);
            visualBlock.transform.localScale = Vector3.zero;
            visualBlock.transform.DOScale(Vector3.one, _globalAnimationDuration.Value);
        }