GameOverScreen.cs 4.4 KB

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