NetRumbleGame.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // NetRumbleGame.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.IO;
  12. using System.Collections.Generic;
  13. using System.Reflection;
  14. using Microsoft.Xna.Framework;
  15. using Microsoft.Xna.Framework.Content;
  16. using Microsoft.Xna.Framework.GamerServices;
  17. using Microsoft.Xna.Framework.Graphics;
  18. using Microsoft.Xna.Framework.Net;
  19. using Microsoft.Xna.Framework.Storage;
  20. #endregion
  21. namespace NetRumble
  22. {
  23. /// <summary>
  24. /// While this used to be an enum in the XNA Framework API, it was removed in version 4.0.
  25. /// However, it is still useful as a parameter to specify what kind of particles to draw,
  26. /// so it is revitalized here as a global enum.
  27. /// </summary>
  28. public enum SpriteBlendMode
  29. {
  30. Additive,
  31. AlphaBlend
  32. }
  33. /// <summary>
  34. /// The main type for this game.
  35. /// </summary>
  36. public class NetRumbleGame : Microsoft.Xna.Framework.Game
  37. {
  38. #region Graphics Data
  39. /// <summary>
  40. /// The graphics device manager used to render the game.
  41. /// </summary>
  42. GraphicsDeviceManager graphics;
  43. #endregion
  44. #region Game State Management Data
  45. /// <summary>
  46. /// The manager for all of the user-interface data.
  47. /// </summary>
  48. ScreenManager screenManager;
  49. #endregion
  50. #region Initialization Methods
  51. /// <summary>
  52. /// Constructs a new NetRumbleGame object.
  53. /// </summary>
  54. public NetRumbleGame()
  55. {
  56. // initialize the graphics device manager
  57. graphics = new GraphicsDeviceManager(this);
  58. graphics.PreferredBackBufferWidth = 1280;
  59. graphics.PreferredBackBufferHeight = 720;
  60. // initialize the content manager
  61. Content.RootDirectory = "Content";
  62. // initialize the gamer-services component
  63. // this component enables Live sign-in functionality
  64. // and updates the Gamer.SignedInGamers collection.
  65. Components.Add(new GamerServicesComponent(this));
  66. // initialize the screen manager
  67. screenManager = new ScreenManager(this);
  68. Components.Add(screenManager);
  69. // initialize the audio system
  70. //AudioManager.Initialize(this, new DirectoryInfo(Content.RootDirectory + @"\audio\wav"));
  71. AudioManager.Initialize(this, new DirectoryInfo(Path.Combine(Content.RootDirectory,@"Audio/wav")));
  72. }
  73. /// <summary>
  74. /// Allows the game to perform any initialization it needs to before starting.
  75. /// This is where it can query for any required services and load any
  76. /// non-graphic related content. Calling base.Initialize will enumerate through
  77. /// any components and initialize them as well.
  78. /// </summary>
  79. protected override void Initialize()
  80. {
  81. base.Initialize();
  82. // Useful to turn on SimulateTrialMode here if you want to test launching the game
  83. // from an invite and have it start in trial mode.
  84. //#if DEBUG
  85. // Guide.SimulateTrialMode = true;
  86. //#endif
  87. // load the initial screens
  88. screenManager.AddScreen(new BackgroundScreen());
  89. screenManager.AddScreen(new MainMenuScreen());
  90. // hookup the invite event-processing function
  91. NetworkSession.InviteAccepted += new EventHandler<InviteAcceptedEventArgs>(NetworkSession_InviteAccepted);
  92. }
  93. /// <summary>
  94. /// Begins the asynchronous process of joining a game from an invitation.
  95. /// </summary>
  96. void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
  97. {
  98. if (Guide.IsTrialMode)
  99. {
  100. screenManager.invited = e.Gamer;
  101. string message = "Need to unlock full version before you can accept this invite.";
  102. MessageBoxScreen messageBox = new MessageBoxScreen(message);
  103. screenManager.AddScreen(messageBox);
  104. System.Console.WriteLine("Cannot accept invite yet because we're in trial mode");
  105. return;
  106. }
  107. // We will join the game from a method in this screen.
  108. MainMenuScreen mainMenu = null;
  109. // Keep the background screen and main menu screen but remove all others
  110. // to prepare for joining the game we were invited to.
  111. foreach (GameScreen screen in screenManager.GetScreens())
  112. {
  113. if (screen is BackgroundScreen)
  114. {
  115. continue;
  116. }
  117. else if (screen is MainMenuScreen)
  118. {
  119. mainMenu = screen as MainMenuScreen;
  120. }
  121. else
  122. {
  123. // If there's an active network session, we'll need to end it
  124. // before attempting to join a new one.
  125. MethodInfo method = screen.GetType().GetMethod("EndSession");
  126. if (method != null)
  127. {
  128. method.Invoke(screen, null);
  129. }
  130. // Now exit and remove this screen.
  131. screen.ExitScreen();
  132. screenManager.RemoveScreen(screen);
  133. }
  134. }
  135. // Now attempt to join the game to which we were invited!
  136. if (mainMenu != null)
  137. mainMenu.JoinInvitedGame();
  138. }
  139. #endregion
  140. #region Drawing Methods
  141. /// <summary>
  142. /// This is called when the game should draw itself.
  143. /// </summary>
  144. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  145. protected override void Draw(GameTime gameTime)
  146. {
  147. graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  148. base.Draw(gameTime);
  149. }
  150. #endregion
  151. #region Entry Point
  152. // /// <summary>
  153. // /// The main entry point for the application.
  154. // /// </summary>
  155. // static class Program
  156. // {
  157. // static void Main()
  158. // {
  159. // using (NetRumbleGame game = new NetRumbleGame())
  160. // {
  161. // game.Run();
  162. // }
  163. // }
  164. // }
  165. #endregion
  166. }
  167. }