GameOverScreen.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 RolePlaying.Data;
  12. using System.IO;
  13. namespace RolePlaying
  14. {
  15. /// <summary>
  16. /// Displays the game-over screen, after the player has lost.
  17. /// </summary>
  18. class GameOverScreen : GameScreen
  19. {
  20. private Texture2D backTexture;
  21. private Texture2D selectIconTexture;
  22. private Texture2D fadeTexture;
  23. private Vector2 backgroundPosition;
  24. private Vector2 titlePosition;
  25. private Vector2 gameOverPosition;
  26. private Vector2 selectPosition;
  27. private Vector2 selectIconPosition;
  28. private readonly string titleString = "Game Over";
  29. private readonly string gameOverString = "The party has been defeated.";
  30. private readonly string selectString = "Continue";
  31. /// <summary>
  32. /// Create a new GameOverScreen object.
  33. /// </summary>
  34. public GameOverScreen()
  35. : base()
  36. {
  37. AudioManager.PushMusic("LoseTheme");
  38. this.Exiting += new EventHandler(GameOverScreen_Exiting);
  39. }
  40. void GameOverScreen_Exiting(object sender, EventArgs e)
  41. {
  42. AudioManager.PopMusic();
  43. }
  44. /// <summary>
  45. /// Load the graphics data from the content manager.
  46. /// </summary>
  47. public override void LoadContent()
  48. {
  49. ContentManager content = ScreenManager.Game.Content;
  50. fadeTexture = content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "FadeScreen"));
  51. backTexture = content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "PopupScreen"));
  52. selectIconTexture = content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "AButton"));
  53. backgroundPosition.X = (Session.BACK_BUFFER_WIDTH - backTexture.Width) / 2;
  54. backgroundPosition.Y = (Session.BACK_BUFFER_HEIGHT - backTexture.Height) / 2;
  55. titlePosition.X = (Session.BACK_BUFFER_WIDTH -
  56. Fonts.HeaderFont.MeasureString(titleString).X) / 2;
  57. titlePosition.Y = backgroundPosition.Y + 70f;
  58. gameOverPosition.X = (Session.BACK_BUFFER_WIDTH -
  59. Fonts.ButtonNamesFont.MeasureString(titleString).X) / 2;
  60. gameOverPosition.Y = backgroundPosition.Y + backTexture.Height / 2;
  61. selectIconPosition.X = Session.BACK_BUFFER_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.InputAction.Ok) ||
  73. InputManager.IsActionTriggered(InputManager.InputAction.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(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  87. // Draw fading screen
  88. spriteBatch.Draw(fadeTexture, new Rectangle(0, 0, Session.BACK_BUFFER_WIDTH, Session.BACK_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. }