NetRumbleGame.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #if LINUX || MONOMAC || LINUX || WINDOWS
  59. graphics.PreferredBackBufferWidth = 1280;
  60. graphics.PreferredBackBufferHeight = 720;
  61. #else
  62. graphics.IsFullScreen = true;
  63. #endif
  64. // initialize the content manager
  65. Content.RootDirectory = "Content";
  66. // initialize the gamer-services component
  67. // this component enables Live sign-in functionality
  68. // and updates the Gamer.SignedInGamers collection.
  69. Components.Add(new GamerServicesComponent(this));
  70. // initialize the screen manager
  71. screenManager = new ScreenManager(this);
  72. Components.Add(screenManager);
  73. // initialize the audio system
  74. //AudioManager.Initialize(this, new DirectoryInfo(Content.RootDirectory + @"\audio\wav"));
  75. AudioManager.Initialize(this, new DirectoryInfo(Path.Combine(Content.RootDirectory,@"Audio/wav")));
  76. }
  77. /// <summary>
  78. /// Allows the game to perform any initialization it needs to before starting.
  79. /// This is where it can query for any required services and load any
  80. /// non-graphic related content. Calling base.Initialize will enumerate through
  81. /// any components and initialize them as well.
  82. /// </summary>
  83. protected override void Initialize()
  84. {
  85. base.Initialize();
  86. // Useful to turn on SimulateTrialMode here if you want to test launching the game
  87. // from an invite and have it start in trial mode.
  88. //#if DEBUG
  89. // Guide.SimulateTrialMode = true;
  90. //#endif
  91. // load the initial screens
  92. screenManager.AddScreen(new BackgroundScreen());
  93. screenManager.AddScreen(new MainMenuScreen());
  94. // hookup the invite event-processing function
  95. NetworkSession.InviteAccepted += new EventHandler<InviteAcceptedEventArgs>(NetworkSession_InviteAccepted);
  96. }
  97. /// <summary>
  98. /// Begins the asynchronous process of joining a game from an invitation.
  99. /// </summary>
  100. void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
  101. {
  102. if (Guide.IsTrialMode)
  103. {
  104. screenManager.invited = e.Gamer;
  105. string message = "Need to unlock full version before you can accept this invite.";
  106. MessageBoxScreen messageBox = new MessageBoxScreen(message);
  107. screenManager.AddScreen(messageBox);
  108. System.Console.WriteLine("Cannot accept invite yet because we're in trial mode");
  109. return;
  110. }
  111. // We will join the game from a method in this screen.
  112. MainMenuScreen mainMenu = null;
  113. // Keep the background screen and main menu screen but remove all others
  114. // to prepare for joining the game we were invited to.
  115. foreach (GameScreen screen in screenManager.GetScreens())
  116. {
  117. if (screen is BackgroundScreen)
  118. {
  119. continue;
  120. }
  121. else if (screen is MainMenuScreen)
  122. {
  123. mainMenu = screen as MainMenuScreen;
  124. }
  125. else
  126. {
  127. // If there's an active network session, we'll need to end it
  128. // before attempting to join a new one.
  129. MethodInfo method = screen.GetType().GetMethod("EndSession");
  130. if (method != null)
  131. {
  132. method.Invoke(screen, null);
  133. }
  134. // Now exit and remove this screen.
  135. screen.ExitScreen();
  136. screenManager.RemoveScreen(screen);
  137. }
  138. }
  139. // Now attempt to join the game to which we were invited!
  140. if (mainMenu != null)
  141. mainMenu.JoinInvitedGame();
  142. }
  143. #endregion
  144. #region Drawing Methods
  145. /// <summary>
  146. /// This is called when the game should draw itself.
  147. /// </summary>
  148. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  149. protected override void Draw(GameTime gameTime)
  150. {
  151. graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  152. base.Draw(gameTime);
  153. }
  154. #endregion
  155. #region Entry Point
  156. // /// <summary>
  157. // /// The main entry point for the application.
  158. // /// </summary>
  159. // static class Program
  160. // {
  161. // static void Main()
  162. // {
  163. // using (NetRumbleGame game = new NetRumbleGame())
  164. // {
  165. // game.Run();
  166. // }
  167. // }
  168. // }
  169. #endregion
  170. }
  171. }