Пример #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(backgroundColor);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);

            DisplayScore();

            if (gameState == GameState.Start)
            {
                string  welcomeMsg = "Welcome to Pong!";
                string  beginMsg   = "Press Enter to begin!";
                Vector2 msgSize    = smallFont.MeasureString(welcomeMsg);
                spriteBatch.DrawString(smallFont, welcomeMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 10), Color.White);
                msgSize = smallFont.MeasureString(beginMsg);
                spriteBatch.DrawString(smallFont, beginMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 20), Color.White);
            }
            else if (gameState == GameState.Serve)
            {
                string  servingPlayerMsg = "Player " + servingPlayer + "'s serve!";
                string  serveMsg         = "Press Enter to serve!";
                Vector2 msgSize          = smallFont.MeasureString(servingPlayerMsg);
                spriteBatch.DrawString(smallFont, servingPlayerMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 10), Color.White);
                msgSize = smallFont.MeasureString(serveMsg);
                spriteBatch.DrawString(smallFont, serveMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 20), Color.White);
            }
            else if (gameState == GameState.Done)
            {
                string  winingPlayerMsg = "Player " + winningPlayer + " Wins!";
                string  restartMsg      = "Press Enter to Restart!";
                Vector2 msgSize         = largeFont.MeasureString(winingPlayerMsg);
                spriteBatch.DrawString(largeFont, winingPlayerMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 10), Color.White);
                msgSize = smallFont.MeasureString(restartMsg);
                spriteBatch.DrawString(smallFont, restartMsg, new Vector2((VIRTUAL_WIDTH / 2) - (msgSize.X / 2), 30), Color.White);
            }

            player1.Render(spriteBatch);
            player2.Render(spriteBatch);
            ball.Render(spriteBatch);

            spriteBatch.End();
            base.Draw(gameTime);
        }