GameOverScreen.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GameOverScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using Microsoft.Xna.Framework.Content;
  14. using RolePlayingGameData;
  15. #endregion
  16. namespace RolePlaying
  17. {
  18. /// <summary>
  19. /// Displays the game-over screen, after the player has lost.
  20. /// </summary>
  21. class GameOverScreen : GameScreen
  22. {
  23. #region Graphics Data
  24. private Texture2D backTexture;
  25. private Texture2D selectIconTexture;
  26. private Texture2D fadeTexture;
  27. private Vector2 backgroundPosition;
  28. private Vector2 titlePosition;
  29. private Vector2 gameOverPosition;
  30. private Vector2 selectPosition;
  31. private Vector2 selectIconPosition;
  32. #endregion
  33. #region Text Data
  34. private readonly string titleString = "Game Over";
  35. private readonly string gameOverString = "The party has been defeated.";
  36. private readonly string selectString = "Continue";
  37. #endregion
  38. #region Initialization
  39. /// <summary>
  40. /// Create a new GameOverScreen object.
  41. /// </summary>
  42. public GameOverScreen()
  43. : base()
  44. {
  45. AudioManager.PushMusic("LoseTheme");
  46. this.Exiting += new EventHandler(GameOverScreen_Exiting);
  47. }
  48. void GameOverScreen_Exiting(object sender, EventArgs e)
  49. {
  50. AudioManager.PopMusic();
  51. }
  52. /// <summary>
  53. /// Load the graphics data from the content manager.
  54. /// </summary>
  55. public override void LoadContent()
  56. {
  57. ContentManager content = ScreenManager.Game.Content;
  58. Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
  59. fadeTexture = content.Load<Texture2D>(@"Textures\GameScreens\FadeScreen");
  60. backTexture = content.Load<Texture2D>(@"Textures\GameScreens\PopupScreen");
  61. selectIconTexture = content.Load<Texture2D>(@"Textures\Buttons\AButton");
  62. backgroundPosition.X = (viewport.Width - backTexture.Width) / 2;
  63. backgroundPosition.Y = (viewport.Height - backTexture.Height) / 2;
  64. titlePosition.X = (viewport.Width -
  65. Fonts.HeaderFont.MeasureString(titleString).X) / 2;
  66. titlePosition.Y = backgroundPosition.Y + 70f;
  67. gameOverPosition.X = (viewport.Width -
  68. Fonts.ButtonNamesFont.MeasureString(titleString).X) / 2;
  69. gameOverPosition.Y = backgroundPosition.Y + backTexture.Height / 2;
  70. selectIconPosition.X = viewport.Width / 2 + 260;
  71. selectIconPosition.Y = backgroundPosition.Y + 530f;
  72. selectPosition.X = selectIconPosition.X -
  73. Fonts.ButtonNamesFont.MeasureString(selectString).X - 10f;
  74. selectPosition.Y = backgroundPosition.Y + 530f;
  75. }
  76. #endregion
  77. #region Updating
  78. /// <summary>
  79. /// Handles user input.
  80. /// </summary>
  81. public override void HandleInput()
  82. {
  83. if (InputManager.IsActionTriggered(InputManager.Action.Ok) ||
  84. InputManager.IsActionTriggered(InputManager.Action.Back))
  85. {
  86. ExitScreen();
  87. ScreenManager.AddScreen(new MainMenuScreen());
  88. return;
  89. }
  90. }
  91. #endregion
  92. #region Drawing
  93. /// <summary>
  94. /// Draws the screen.
  95. /// </summary>
  96. public override void Draw(GameTime gameTime)
  97. {
  98. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  99. spriteBatch.Begin();
  100. // Draw fading screen
  101. spriteBatch.Draw(fadeTexture, new Rectangle(0, 0, 1280, 720), Color.White);
  102. // Draw popup texture
  103. spriteBatch.Draw(backTexture, backgroundPosition, Color.White);
  104. // Draw title
  105. spriteBatch.DrawString(Fonts.HeaderFont, titleString, titlePosition,
  106. Fonts.TitleColor);
  107. // Draw Gameover text
  108. spriteBatch.DrawString(Fonts.ButtonNamesFont, gameOverString,
  109. gameOverPosition, Fonts.CountColor);
  110. // Draw select button
  111. spriteBatch.DrawString(Fonts.ButtonNamesFont, selectString, selectPosition,
  112. Color.White);
  113. spriteBatch.Draw(selectIconTexture, selectIconPosition, Color.White);
  114. spriteBatch.End();
  115. }
  116. #endregion
  117. }
  118. }