/// <summary> /// Draws the gameplay screen. /// </summary> public override void Draw(GameTime gameTime) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; if (networkSession != null) { // make sure we know what the local ship is if ((localShip == null) && (networkSession.LocalGamers.Count > 0)) { PlayerData playerData = networkSession.LocalGamers[0].Tag as PlayerData; if (playerData.Ship != null) { localShip = playerData.Ship; starfield.Reset(localShip.Position); } } if (bloomComponent != null) { bloomComponent.BeginDraw(); } // draw the world if ((world != null) && (localShip != null) && !IsExiting) { Vector2 center = new Vector2( localShip.Position.X + ScreenManager.GraphicsDevice.Viewport.X - ScreenManager.GraphicsDevice.Viewport.Width / 2, localShip.Position.Y + ScreenManager.GraphicsDevice.Viewport.Y - ScreenManager.GraphicsDevice.Viewport.Height / 2); starfield.Draw(center); world.Draw(elapsedTime, center); if (bloomComponent != null) { bloomComponent.Draw(gameTime); } } // draw the user-interface elements of the game (scores, etc.) DrawHud((float)gameTime.TotalGameTime.TotalSeconds); } // If the game is transitioning on or off, fade it out to black. if (ScreenState == ScreenState.TransitionOn && (TransitionPosition > 0)) { ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha); } }
/// <summary> /// Draws the message box. /// </summary> public override void Draw(GameTime gameTime) { // Darken down any other screens that were drawn beneath the popup. ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3); // Center the message text in the viewport. Viewport viewport = ScreenManager.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = ScreenManager.Font.MeasureString(message); Vector2 textPosition = (viewportSize - textSize) / 2; Vector2 usageTextSize = smallFont.MeasureString(usageText); Vector2 usageTextPosition = (viewportSize - usageTextSize) / 2; usageTextPosition.Y = textPosition.Y + ScreenManager.Font.LineSpacing * 1.1f; // Fade the popup alpha during transitions. Color color = new Color(255, 255, 255, TransitionAlpha); // Draw the background rectangles Rectangle rect = new Rectangle( (int)(Math.Min(usageTextPosition.X, textPosition.X)), (int)(textPosition.Y), (int)(Math.Max(usageTextSize.X, textSize.X)), (int)(ScreenManager.Font.LineSpacing * 1.1f + usageTextSize.Y) ); rect.X -= (int)(0.1f * rect.Width); rect.Y -= (int)(0.1f * rect.Height); rect.Width += (int)(0.2f * rect.Width); rect.Height += (int)(0.2f * rect.Height); Rectangle rect2 = new Rectangle(rect.X - 1, rect.Y - 1, rect.Width + 2, rect.Height + 2); ScreenManager.DrawRectangle(rect2, new Color(128, 128, 128, (byte)(192.0f * (float)TransitionAlpha / 255.0f))); ScreenManager.DrawRectangle(rect, new Color(0, 0, 0, (byte)(232.0f * (float)TransitionAlpha / 255.0f))); // Draw the message box text. ScreenManager.SpriteBatch.Begin(); ScreenManager.SpriteBatch.DrawString(ScreenManager.Font, message, textPosition, color); ScreenManager.SpriteBatch.DrawString(smallFont, usageText, usageTextPosition, color); ScreenManager.SpriteBatch.End(); }