NetworkStateManagementGame.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //-----------------------------------------------------------------------------
  2. // Game.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. using Microsoft.Xna.Framework.Net;
  11. namespace NetworkStateManagement
  12. {
  13. /// <summary>
  14. /// Sample showing how to manage the different game states involved in
  15. /// implementing a networked game, with menus for creating, searching,
  16. /// and joining sessions, a lobby screen, and the game itself. This main
  17. /// game class is extremely simple: all the interesting stuff happens
  18. /// in the ScreenManager component.
  19. /// </summary>
  20. public class NetworkStateManagementGame : Game
  21. {
  22. const int screenWidth = 480;
  23. const int screenHeight = 540;
  24. GraphicsDeviceManager graphics;
  25. ScreenManager screenManager;
  26. // By preloading any assets used by UI rendering, we avoid framerate glitches
  27. // when they suddenly need to be loaded in the middle of a menu transition.
  28. static readonly string[] preloadAssets =
  29. {
  30. "gradient",
  31. "cat",
  32. "chat_ready",
  33. "chat_able",
  34. "chat_talking",
  35. "chat_mute",
  36. };
  37. /// <summary>
  38. /// The main game constructor.
  39. /// </summary>
  40. public NetworkStateManagementGame()
  41. {
  42. Content.RootDirectory = "Content";
  43. graphics = new GraphicsDeviceManager(this);
  44. #if MOBILE
  45. graphics.IsFullScreen = true;
  46. #endif
  47. graphics.PreferredBackBufferWidth = screenWidth;
  48. graphics.PreferredBackBufferHeight = screenHeight;
  49. // Create components.
  50. screenManager = new ScreenManager(this);
  51. Components.Add(screenManager);
  52. Components.Add(new MessageDisplayComponent(this));
  53. Components.Add(new GamerServicesComponent(this));
  54. // Activate the first screens.
  55. screenManager.AddScreen(new BackgroundScreen(), null);
  56. screenManager.AddScreen(new MainMenuScreen(), null);
  57. // Listen for invite notification events.
  58. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted(screenManager, e);
  59. // To test the trial mode behavior while developing your game,
  60. // uncomment this line:
  61. // Guide.SimulateTrialMode = true;
  62. }
  63. /// <summary>
  64. /// Loads graphics content.
  65. /// </summary>
  66. protected override void LoadContent()
  67. {
  68. foreach (string asset in preloadAssets)
  69. {
  70. Content.Load<object>(asset);
  71. }
  72. }
  73. /// <summary>
  74. /// This is called when the game should draw itself.
  75. /// </summary>
  76. protected override void Draw(GameTime gameTime)
  77. {
  78. graphics.GraphicsDevice.Clear(Color.Black);
  79. // The real drawing happens inside the screen manager component.
  80. base.Draw(gameTime);
  81. }
  82. }
  83. }