protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); pe.Graphics.Clear(Color.FromArgb(5, 5, 20)); Brush b; foreach (Block block in Board.GetBlocks()) { pe.Graphics.DrawImage(GetImageFromColor(block.Color), block.X * 25, block.Y * 25, 25, 25); } Piece ghostPiece = Board.FallLocation(); foreach (Block block in ghostPiece.Blocks) { //pe.Graphics.DrawImage(GetImageFromColor(block.Color), (block.X + ghostPiece.X) * 25, (block.Y + ghostPiece.Y) * 25, 25, 25); pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(77, ColorFromInt(block.Color))), (block.X + ghostPiece.X) * 25, (block.Y + ghostPiece.Y) * 25, 25, 25); } b = new SolidBrush(Color.FromArgb(5, 10, 40)); for (int x = 1; x < 10; x++) { pe.Graphics.DrawLine(new Pen(b), x * 25, 0, x * 25, Height); } for (int y = 1; y < 20; y++) { pe.Graphics.DrawLine(new Pen(b), 0, y * 25, Width, y * 25); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(new Color(5, 5, 20)); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied); for (int y = 1; y < 20; y++) { spriteBatch.DrawLine(0, y * 32, 32 * 10, y * 32, lineColor, 2f); } for (int x = 1; x < 10; x++) { spriteBatch.DrawLine(x * 32, 0, x * 32, 32 * 20, lineColor, 2f); } spriteBatch.DrawLine(10 * 32 + 2, 0, 10 * 32 + 2, Window.ClientBounds.Height, lineColor, 4f); Piece nextPiece = tetrisBoard.PieceQueue[0].Normalize(); // TODO: Center pieces. DrawBlocks(ref spriteBatch, nextPiece.Normalize().Blocks, 32 * 10 + 65, 30, 0.7f, true); DrawBlocks(ref spriteBatch, tetrisBoard.PieceQueue[1].Normalize().Blocks, 32 * 10 + 65, 90, 0.5f, true); DrawBlocks(ref spriteBatch, tetrisBoard.PieceQueue[2].Normalize().Blocks, 32 * 10 + 65, 140, 0.5f, true); DrawBlocks(ref spriteBatch, tetrisBoard.PieceQueue[3].Normalize().Blocks, 32 * 10 + 65, 190, 0.5f, true); DrawBlocks(ref spriteBatch, tetrisBoard.PieceQueue[4].Normalize().Blocks, 32 * 10 + 65, 240, 0.5f, true); DrawBlocks(ref spriteBatch, tetrisBoard.PieceQueue[5].Normalize().Blocks, 32 * 10 + 65, 290, 0.5f, true); spriteBatch.DrawRectangle(new Vector2(32 * 10 + 20, 365), new Size2(110, 110), lineColorB, 4); if (tetrisBoard.HeldPiece.HasValue) { DrawBlocks(ref spriteBatch, tetrisBoard.HeldPiece.Value.Normalize().Blocks, 32 * 10 + 65, 410, 0.6f, true); } Piece ghostPiece = tetrisBoard.FallLocation(); foreach (Block b in ghostPiece.Blocks) { spriteBatch.Draw(tetrisBlocks[b.Color], new Vector2((b.X + ghostPiece.X) * 32, (b.Y + ghostPiece.Y) * 32), new Color(Color.White, 0.3f)); } DrawBlocks(ref spriteBatch, tetrisBoard.GetBlocks().ToArray(), 0, 0); if (tetrisBoard.IsOver) { spriteBatch.FillRectangle(new Vector2(0, 0), new Vector2(Window.ClientBounds.Width, Window.ClientBounds.Height), new Color(5, 5, 20, 128)); DrawStringCenter(ref spriteBatch, eightyFour, "Game Over", new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2), Color.White); DrawStringCenter(ref spriteBatch, eightyFourSmall, "R to Restart", new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2 + 50), Color.White); } spriteBatch.End(); base.Draw(gameTime); }