/// <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.White); // TODO: Add your drawing code here spriteBatch.Begin(); ball.Draw(spriteBatch, false); player1.Draw(spriteBatch, false); player2.Draw(spriteBatch, false); spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); leftPaddle.Draw(spriteBatch); rightPaddle.Draw(spriteBatch); ball.Draw(spriteBatch); string tempString = $"Left Score: {leftScore}"; spriteBatch.DrawString(mainFont, tempString, new Vector2(50, 50), Color.Black); tempString = $"Right Score: {rightScore}"; spriteBatch.DrawString(mainFont, tempString, new Vector2(screenWidth - mainFont.MeasureString(tempString).X - 50, 50), Color.Black); tempString = $"First to {scoreToReach} wins"; spriteBatch.DrawString(mainFont, tempString, new Vector2(screenWidth / 2 - mainFont.MeasureString(tempString).X / 2, 50), Color.Black); if (currentState == GameState.Paused) { tempString = "Press space to continue"; spriteBatch.DrawString(mainFont, tempString, new Vector2(screenWidth / 2 - mainFont.MeasureString(tempString).X / 2, screenHeight / 2 - mainFont.MeasureString(tempString).Y / 2), Color.Red); } else if (currentState == GameState.LeftWins) { tempString = "Left Won! Press space to restart"; spriteBatch.DrawString(mainFont, tempString, new Vector2(screenWidth / 2 - mainFont.MeasureString(tempString).X / 2, screenHeight / 2 - mainFont.MeasureString(tempString).Y / 2), Color.Red); } else if (currentState == GameState.RightWins) { tempString = "Right Won! Press space to restart"; spriteBatch.DrawString(mainFont, tempString, new Vector2(screenWidth / 2 - mainFont.MeasureString(tempString).X / 2, screenHeight / 2 - mainFont.MeasureString(tempString).Y / 2), Color.Red); } spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { _graphics.GraphicsDevice.Clear(Color.Black); _spriteBatch.Begin(); // Draw different things based on the state switch (_state) { case ClientState.EstablishingConnection: _drawCentered(_establishingConnectionMsg); Window.Title = String.Format("Pong -- Connecting to {0}:{1}", ServerHostname, ServerPort); break; case ClientState.WaitingForGameStart: _drawCentered(_waitingForGameStartMsg); Window.Title = String.Format("Pong -- Waiting for 2nd Player"); break; case ClientState.InGame: // Draw game objects _ball.Draw(gameTime, _spriteBatch); _left.Draw(gameTime, _spriteBatch); _right.Draw(gameTime, _spriteBatch); // Change the window title _updateWindowTitleWithScore(); break; case ClientState.GameOver: _drawCentered(_gamveOverMsg); _updateWindowTitleWithScore(); break; } _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Draws the gameplay screen. /// </summary> public override void Draw(GameTime gameTime) { // This game has a blue background. Why? Because! ScreenManager.GraphicsDevice.Clear(Color.Black); // Our player and enemy are both actually just text strings. SpriteBatch spriteBatch = ScreenManager.SpriteBatch; spriteBatch.Begin(); //Pong players player1.Draw(spriteBatch); player2.Draw(spriteBatch); //Pong ball ball.Draw(spriteBatch); //Draw Score board spriteBatch.DrawString(font, "" + player1.Score, player1Score, Color.Red); spriteBatch.DrawString(font, "" + player2.Score, player2Score, Color.Red); //Draw Top and bottom borders player1Score = new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 3, 0); player2Score = new Vector2(ScreenManager.GraphicsDevice.Viewport.Width * 2 / 3 - 15, 0); spriteBatch.Draw(borderTexture, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f); spriteBatch.Draw(borderTexture, new Vector2(0, ScreenManager.GraphicsDevice.Viewport.Height - borderTexture.Height), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f); //Displays the winner when the score to win has been reached if (player1.Score == playerScoreWin) { spriteBatch.DrawString(font, "Player1 Wins!", new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 5, (ScreenManager.GraphicsDevice.Viewport.Height / 2) + font.LineSpacing), Color.Orchid); } else if (player2.Score == playerScoreWin) { spriteBatch.DrawString(font, "Player2 Wins!", new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 5, (ScreenManager.GraphicsDevice.Viewport.Height / 2) + font.LineSpacing), Color.Orchid); } //Displays a notice to the user to press enter to start game if (!startGame) { spriteBatch.DrawString(font, "Press Enter", new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 4, ScreenManager.GraphicsDevice.Viewport.Height - font.LineSpacing), Color.Aqua); } spriteBatch.End(); // If the game is transitioning on or off, fade it out to black. if (TransitionPosition > 0 || pauseAlpha > 0) { float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2); ScreenManager.FadeBackBufferToBlack(alpha); } }