예제 #1
0
        /// <summary>
        /// Draws the gameplay area to the RenderTarget.
        /// </summary>
        protected void DrawLevel()
        {
            //Set up drawing pass to the RenderTarget
            ScreenManager.GraphicsDevice.SetRenderTarget(gameField);
            ScreenManager.GraphicsDevice.Clear(Color.Black);

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();

            int[,] levelMatrix = currentLevel.LevelGrid();

            //Loop through all registered blocks in the LevelGrid
            for (int x = 0; x < levelWidth; x++)
            {
                for (int y = 0; y < levelHeight; y++)
                {
                    if (levelMatrix[x, y] > 0)
                    {
                        //Draw the block
                        spriteBatch.Draw(blockTexture,
                                         new Rectangle((x * blockSize),
                                                       (y * blockSize),
                                                       blockSize,
                                                       blockSize),
                                         BlockColors.GetColor(levelMatrix[x, y]));
                    }
                }
            }

            //End the drawing pass
            spriteBatch.End();
        }
예제 #2
0
        protected void DrawPreviewField()
        {
            //Get the block that should be put in the previewfield.
            Block nextBlock = currentLevel.NextBlock;

            //Because we want this preview block to be centered, we will not observe the matrix for drawing it.
            //Instead we will calculate an offset for it to be centered.
            int offSetX = (4 - nextBlock.Width) * (blockSize / 2);
            int offSetY = (4 - nextBlock.Height) * (blockSize / 2);

            //Set up drawing pass to the RenderTarget
            ScreenManager.GraphicsDevice.SetRenderTarget(previewField);
            ScreenManager.GraphicsDevice.Clear(Color.Black);

            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();

            //Loop through all the individual blocks within the next shape.
            for (int x = 0; x < nextBlock.Width; x++)
            {
                for (int y = 0; y < nextBlock.Height; y++)
                {
                    if (nextBlock.Shape[x, y] > 0)
                    {
                        //Draw the square block
                        spriteBatch.Draw(blockTexture,
                                         new Rectangle(offSetX + (x * blockSize),
                                                       offSetY + (y * blockSize),
                                                       blockSize,
                                                       blockSize),
                                         BlockColors.GetColor(nextBlock.Shape[x, y]));
                    }
                }
            }

            //End the drawing pass.
            spriteBatch.End();
        }