Exemplo n.º 1
0
        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            //Draw score and level
            spriteBatch.DrawString(Tetris.font, _score.ToString(), _offset + new Vector2(0, _holdGrid.Height) * Tetronimo.BlockSize, Color.White, 0, new Vector2(Tetris.font.MeasureString(_score.ToString()).X, 0), 0.75f, SpriteEffects.None, 0);
            string level = "Level: " + Math.Min(_clearedLines / LinesPerLevel, MaxLevel);

            spriteBatch.DrawString(Tetris.font, level, _offset + new Vector2(0, _holdGrid.Height + 1) * Tetronimo.BlockSize, Color.White, 0, new Vector2(Tetris.font.MeasureString(level).X, 0), 0.75f, SpriteEffects.None, 0);

            for (int x = -1; x <= _grid.GetLength(0); x++)
            {
                for (int y = -1; y <= _grid.GetLength(1); y++)
                {
                    bool isOutline = x == -1 || y == -1 || x == _grid.GetLength(0) || y == _grid.GetLength(1);                                                //check if the coordinate is part of the outline
                    spriteBatch.Draw(Tetronimo.block, new Vector2(x + 1, y + 1) * Tetronimo.BlockSize + _offset, isOutline ? _outline : colors[_grid[x, y]]); //draw the blocks for the outline or grid
                }
            }

            //Draw the hold grid
            DrawRectangle(spriteBatch, _holdGrid);
            DrawRectangle(spriteBatch, _nextGrid);

            //draw the tetronimos that are in the grids
            DrawTetronimoInRect(spriteBatch, _holdTetronimo, _holdGrid);
            DrawTetronimoInRect(spriteBatch, _nextTetronimo, _nextGrid);

            //draw the current tetronimo
            _currentTetronimo?.Draw(spriteBatch, _offset + Tetronimo.BlockSize * (lost ? new Vector2(1, 0) : new Vector2(1, 1)));

            //Display Controls
            spriteBatch.DrawString(Tetris.font, $"Left: {_left.ToString()}\nRight: {_right.ToString()}\nDown: {_down.ToString()}\nRotate: {_rotate.ToString()}\nPlace: {_place.ToString()}\nHold: {_hold.ToString()}", _offset + new Vector2(_grid.GetLength(0) + 2, _holdGrid.Height) * Tetronimo.BlockSize, Color.White, 0, Vector2.Zero, 0.4f, SpriteEffects.None, 0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Draw a tetronimo in a rect
 /// </summary>
 /// <param name="spriteBatch">the thing used to draw</param>
 /// <param name="tetronimo">the tetronimo to draw</param>
 /// <param name="rect">the rect in which to draw</param>
 private void DrawTetronimoInRect(SpriteBatch spriteBatch, Tetronimo tetronimo, Rectangle rect)
 {
     //draws the tetronimo centered in the grid
     tetronimo?.Draw(spriteBatch, _offset + (new Vector2(rect.X, rect.Y) + (new Vector2(rect.Width, rect.Height) - tetronimo.Size) / 2) * Tetronimo.BlockSize);
 }