BackstoryScreen.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //-----------------------------------------------------------------------------
  2. // BackstoryScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Graphics;
  12. using Microsoft.Xna.Framework.Content;
  13. using RolePlaying.Data;
  14. using System.IO;
  15. namespace RolePlaying
  16. {
  17. /// <summary>
  18. /// Shows the backstory screen, explaining the basic game idea to the user.
  19. /// </summary>
  20. class BackstoryScreen : GameScreen
  21. {
  22. private Texture2D backgroundTexture;
  23. private Texture2D plankTexture;
  24. private Vector2 plankPosition;
  25. private Vector2 titlePosition;
  26. private string backstoryText =
  27. "Welcome, hero! You must meet new comrades, earn necessary " +
  28. "experience, gold, spells, and the equipment required to challenge " +
  29. "and defeat the evil Tamar, who resides in his lair, known as the " +
  30. "Unspoken Tower. Be wary! The Unspoken Tower is filled with " +
  31. "monstrosities that only the most hardened of heroes could possibly " +
  32. "face. Good luck!";
  33. private List<string> textLines;
  34. private Texture2D scrollUpTexture;
  35. private readonly Vector2 scrollUpPosition = new Vector2(980, 200);
  36. private Texture2D scrollDownTexture;
  37. private readonly Vector2 scrollDownPosition = new Vector2(980, 460);
  38. private Texture2D lineBorderTexture;
  39. private readonly Vector2 linePosition = new Vector2(200, 570);
  40. private Texture2D backTexture;
  41. private readonly Vector2 backPosition = new Vector2(225, 610);
  42. private int startIndex;
  43. private const int maxLineDisplay = 7;
  44. private const string screenName = "Backstory";
  45. public BackstoryScreen()
  46. : base()
  47. {
  48. textLines = Fonts.BreakTextIntoList(backstoryText, Fonts.DescriptionFont, 590);
  49. }
  50. /// <summary>
  51. /// Loads the graphics content for this screen
  52. /// </summary>
  53. public override void LoadContent()
  54. {
  55. base.LoadContent();
  56. ContentManager content = ScreenManager.Game.Content;
  57. backgroundTexture = content.Load<Texture2D>(Path.Combine("Textures", "MainMenu", "MainMenu"));
  58. plankTexture =
  59. content.Load<Texture2D>(Path.Combine("Textures", "MainMenu", "MainMenuPlank03"));
  60. backTexture =
  61. content.Load<Texture2D>(Path.Combine("Textures", "Buttons", "BButton"));
  62. scrollUpTexture =
  63. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "ScrollUp"));
  64. scrollDownTexture =
  65. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "ScrollDown"));
  66. lineBorderTexture =
  67. content.Load<Texture2D>(Path.Combine("Textures", "GameScreens", "LineBorder"));
  68. plankPosition.X = backgroundTexture.Width / 2 - plankTexture.Width / 2;
  69. plankPosition.Y = 60;
  70. titlePosition.X = plankPosition.X + (plankTexture.Width -
  71. Fonts.HeaderFont.MeasureString(screenName).X) / 2;
  72. titlePosition.Y = plankPosition.Y + (plankTexture.Height -
  73. Fonts.HeaderFont.MeasureString(screenName).Y) / 2;
  74. }
  75. /// <summary>
  76. /// Handles user input.
  77. /// </summary>
  78. public override void HandleInput()
  79. {
  80. // exits the screen
  81. if (InputManager.IsActionTriggered(InputManager.InputAction.Back))
  82. {
  83. ExitScreen();
  84. return;
  85. }
  86. // scroll down
  87. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorDown))
  88. {
  89. // Traverse down the help text
  90. if (startIndex + maxLineDisplay < textLines.Count)
  91. {
  92. startIndex += 1;
  93. }
  94. }
  95. // scroll up
  96. else if (InputManager.IsActionTriggered(InputManager.InputAction.CursorUp))
  97. {
  98. // Traverse up the help text
  99. if (startIndex > 0)
  100. {
  101. startIndex -= 1;
  102. }
  103. }
  104. }
  105. /// <summary>
  106. /// Draws the help screen.
  107. /// </summary>
  108. public override void Draw(GameTime gameTime)
  109. {
  110. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  111. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  112. spriteBatch.Draw(backgroundTexture, Vector2.Zero, Color.White);
  113. spriteBatch.Draw(plankTexture, plankPosition, Color.White);
  114. spriteBatch.Draw(backTexture, backPosition, Color.White);
  115. spriteBatch.Draw(lineBorderTexture, linePosition, Color.White);
  116. spriteBatch.DrawString(Fonts.ButtonNamesFont, "Back",
  117. new Vector2(backPosition.X + 55, backPosition.Y + 5), Color.White);
  118. spriteBatch.Draw(scrollUpTexture, scrollUpPosition, Color.White);
  119. spriteBatch.Draw(scrollDownTexture, scrollDownPosition, Color.White);
  120. spriteBatch.DrawString(Fonts.HeaderFont, screenName, titlePosition, Fonts.TitleColor, MathHelper.ToRadians(-3.0f), Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
  121. for (int i = 0; i < maxLineDisplay; i++)
  122. {
  123. spriteBatch.DrawString(Fonts.DescriptionFont, textLines[startIndex + i],
  124. new Vector2(360, 200 + (Fonts.DescriptionFont.LineSpacing + 10) * i),
  125. Color.Black);
  126. }
  127. spriteBatch.End();
  128. }
  129. }
  130. }