TitleScreen.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // TitleScreen.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 System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. #endregion
  16. namespace Spacewar
  17. {
  18. /// <summary>
  19. /// TitleScreen represents the title screen displayes while media loads and
  20. /// Allows users to select game type
  21. /// </summary>
  22. public class TitleScreen : FullScreenSplash
  23. {
  24. private bool showInfo;
  25. private bool playRetro;
  26. /// <summary>
  27. /// Creates a new titlescreen
  28. /// </summary>
  29. public TitleScreen(Game game)
  30. : base(game, @"textures\spacewar_title_FINAL", TimeSpan.Zero, GameState.ShipSelection)
  31. {
  32. }
  33. /// <summary>
  34. /// Update for TitleScreen waits till the 1st image is displayed then preloads the media
  35. /// </summary>
  36. /// <param name="time">Game Time</param>
  37. /// <param name="elapsedTime">Elapsed Time since last Update</param>
  38. /// <returns>NextGameState</returns>
  39. public override GameState Update(TimeSpan time, TimeSpan elapsedTime)
  40. {
  41. //X displays the intro screen
  42. if (XInputHelper.GamePads[PlayerIndex.One].XPressed || XInputHelper.GamePads[PlayerIndex.Two].XPressed)
  43. {
  44. showInfo = true;
  45. }
  46. //B plays retro or cancels info screen
  47. if (XInputHelper.GamePads[PlayerIndex.One].BPressed || XInputHelper.GamePads[PlayerIndex.Two].BPressed)
  48. {
  49. if (showInfo)
  50. {
  51. showInfo = false;
  52. }
  53. else
  54. {
  55. playRetro = true;
  56. }
  57. }
  58. //Don't allow the base class to quit if the info screen is up
  59. if (showInfo)
  60. {
  61. return GameState.None;
  62. }
  63. else
  64. {
  65. GameState returnValue = base.Update(time, elapsedTime);
  66. //'A' is handled by FullScreenSplash.Update - handle 'B' here
  67. if (playRetro)
  68. returnValue = GameState.PlayRetro;
  69. return returnValue;
  70. }
  71. }
  72. /// <summary>
  73. /// Renders the title screen
  74. /// </summary>
  75. public override void Render()
  76. {
  77. base.Render();
  78. //Once all the media is cached we can show the menu
  79. IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
  80. GraphicsDevice device = graphicsService.GraphicsDevice;
  81. SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque);
  82. device.DepthStencilState = DepthStencilState.None;
  83. if (showInfo)
  84. {
  85. Texture2D infoTexture = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\info_screen");
  86. SpriteBatch.Draw(infoTexture, new Vector2(270, 135), null, Color.White);
  87. }
  88. else
  89. {
  90. Texture2D buttonTexture = SpacewarGame.ContentManager.Load<Texture2D>(SpacewarGame.Settings.MediaPath + @"textures\title_button_overlay");
  91. SpriteBatch.Draw(buttonTexture, new Vector2(950, 450), null, Color.White);
  92. }
  93. SpriteBatch.End();
  94. }
  95. public override void OnCreateDevice()
  96. {
  97. base.OnCreateDevice();
  98. }
  99. }
  100. }