Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }