Exemplo n.º 1
0
    public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
    {
        currentDrawPosition = position;
        Vector2 blockPosition = activeBlock.getLocation();
        Color   blockColor    = activeBlock.getColor();

        bool[,] blockArray = activeBlock.Read();

        Vector2 nextBlockPreviewLocation = new Vector2(400, 140);
        Color   nextBlockColor           = nextBlock.getColor();

        bool[,] nextBlockArray = nextBlock.Read();
        UpdateGrid();

        //draw background grid
        for (int y = 0; y < Height; y++)
        {
            for (int x = 0; x < Width; x++)
            {
                spriteBatch.Draw(emptyCell, currentDrawPosition, grid[y, x]);
                currentDrawPosition.X += 30;
            }
            currentDrawPosition.X  = 0;
            currentDrawPosition.Y += 30;
        }

        //draw active block
        for (int y = 0; y < 4; y++)
        {
            for (int x = 0; x < 4; x++)
            {
                if (blockArray[y, x])
                {
                    spriteBatch.Draw(emptyCell, new Vector2((blockPosition.X + (float)x) * 30, (blockPosition.Y + (float)y) * 30), blockColor);
                }
            }
        }

        //preview of nextBlock
        for (int y = 0; y < 4; y++)
        {
            for (int x = 0; x < 4; x++)
            {
                if (nextBlockArray[y, x])
                {
                    spriteBatch.Draw(emptyCell, new Vector2(nextBlockPreviewLocation.X + (float)x * 30, nextBlockPreviewLocation.Y + (float)y * 30), nextBlockColor);
                }
                else
                {
                    spriteBatch.Draw(emptyCell, new Vector2(nextBlockPreviewLocation.X + (float)x * 30, nextBlockPreviewLocation.Y + (float)y * 30), Color.White);
                }
            }
        }
    }
Exemplo n.º 2
0
        public void add(TetrisBlock currentBlock)
        {
            List<int[]> pos = currentBlock.computeActualPos();
            for (int i = 0; i < pos.Count; i++)
            {
                int[] currentPos = pos[i];
                grid[currentPos[0], currentPos[1]].setEmptyness(false);
                grid[currentPos[0], currentPos[1]].setColor(currentBlock.getColor());

            }
        }