/// <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(Color.Black); // TODO: Add your drawing code here spriteBatch.Begin(); paddle.Draw(); wall.Draw(); gameBorder.Draw(); if (ball.Visible) { bool inPlay = ball.Move(wall, paddle); if (inPlay) { ball.Draw(); } else { ballsRemaining--; readyToServeBall = true; } } staticBall.Draw(); string scoreMsg = "Score: " + ball.Score.ToString("00000"); Vector2 space = gameContent.labelFont.MeasureString(scoreMsg); spriteBatch.DrawString(gameContent.labelFont, scoreMsg, new Vector2((screenWidth - space.X) / 2, screenHeight - 40), Color.White); if (ball.bricksCleared >= 70) { ball.Visible = false; ball.bricksCleared = 0; wall = new Wall(1, 50, spriteBatch, gameContent); readyToServeBall = true; } if (readyToServeBall) { if (ballsRemaining > 0) { string startMsg = "Press <Space> or Click Mouse to Start"; Vector2 startSpace = gameContent.labelFont.MeasureString(startMsg); spriteBatch.DrawString(gameContent.labelFont, startMsg, new Vector2((screenWidth - startSpace.X) / 2, screenHeight / 2), Color.White); } else { string endMsg = "Game Over"; Vector2 endSpace = gameContent.labelFont.MeasureString(endMsg); spriteBatch.DrawString(gameContent.labelFont, endMsg, new Vector2((screenWidth - endSpace.X) / 2, screenHeight / 2), Color.White); } } spriteBatch.DrawString(gameContent.labelFont, ballsRemaining.ToString(), new Vector2(40, 10), Color.White); spriteBatch.End(); base.Draw(gameTime); }
/// <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(Color.Black); spriteBatch.Begin(); _paddle.Draw(); _wall.Draw(); _gameBorder.Draw(); if (_ball.Visible) { bool inPlay = _ball.Move(_wall, _paddle); if (inPlay) { _ball.Draw(); } else { _remainingBalls--; _readyToServeBall = true; } } _staticBall.Draw(); string scoreMsg = "Score: " + _ball.Score.ToString("00000"); Vector2 space = gameContent.LabelFont.MeasureString(scoreMsg); spriteBatch.DrawString(gameContent.LabelFont, scoreMsg, new Vector2((_screenWidth - space.X) / 2, _screenHeight - 40), Color.White); if (_ball.bricksCleared >= 70) { _ball.Visible = false; _ball.bricksCleared = 0; _wall = new _wall(1, 50, spriteBatch, gameContent); _readyToServeBall = true; } if (_readyToServeBall) { if (_remainingBalls > 0) { string startMsg = "Press <Space> or Click Mouse to Start"; Vector2 startSpace = gameContent.LabelFont.MeasureString(startMsg); spriteBatch.DrawString(gameContent.LabelFont, startMsg, new Vector2((_screenWidth - startSpace.X) / 2, _screenHeight / 2), Color.White); } else { string endMsg = "Game Over"; Vector2 endSpace = gameContent.LabelFont.MeasureString(endMsg); spriteBatch.DrawString(gameContent.LabelFont, endMsg, new Vector2((_screenWidth - endSpace.X) / 2, _screenHeight / 2), Color.White); } } spriteBatch.DrawString(gameContent.LabelFont, _remainingBalls.ToString(), new Vector2(40, 10), Color.White); spriteBatch.End(); base.Draw(gameTime); }