123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- #region File Description
- //-----------------------------------------------------------------------------
- // NetRumbleGame.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Reflection;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- #endregion
- namespace NetRumble
- {
- /// <summary>
- /// While this used to be an enum in the XNA Framework API, it was removed in version 4.0.
- /// However, it is still useful as a parameter to specify what kind of particles to draw,
- /// so it is revitalized here as a global enum.
- /// </summary>
- public enum SpriteBlendMode
- {
- Additive,
- AlphaBlend
- }
- /// <summary>
- /// The main type for this game.
- /// </summary>
- public class NetRumbleGame : Microsoft.Xna.Framework.Game
- {
- #region Graphics Data
- /// <summary>
- /// The graphics device manager used to render the game.
- /// </summary>
- GraphicsDeviceManager graphics;
- #endregion
- #region Game State Management Data
- /// <summary>
- /// The manager for all of the user-interface data.
- /// </summary>
- ScreenManager screenManager;
- #endregion
- #region Initialization Methods
- /// <summary>
- /// Constructs a new NetRumbleGame object.
- /// </summary>
- public NetRumbleGame()
- {
- // initialize the graphics device manager
- graphics = new GraphicsDeviceManager(this);
- #if LINUX || MONOMAC || LINUX || WINDOWS
- graphics.PreferredBackBufferWidth = 1280;
- graphics.PreferredBackBufferHeight = 720;
- #else
- graphics.IsFullScreen = true;
- #endif
- // initialize the content manager
- Content.RootDirectory = "Content";
- // initialize the gamer-services component
- // this component enables Live sign-in functionality
- // and updates the Gamer.SignedInGamers collection.
- Components.Add(new GamerServicesComponent(this));
- // initialize the screen manager
- screenManager = new ScreenManager(this);
- Components.Add(screenManager);
- // initialize the audio system
- //AudioManager.Initialize(this, new DirectoryInfo(Content.RootDirectory + @"\audio\wav"));
- AudioManager.Initialize(this, new DirectoryInfo(Path.Combine(Content.RootDirectory,@"Audio/wav")));
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting.
- /// This is where it can query for any required services and load any
- /// non-graphic related content. Calling base.Initialize will enumerate through
- /// any components and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- base.Initialize();
- // Useful to turn on SimulateTrialMode here if you want to test launching the game
- // from an invite and have it start in trial mode.
- //#if DEBUG
- // Guide.SimulateTrialMode = true;
- //#endif
- // load the initial screens
- screenManager.AddScreen(new BackgroundScreen());
- screenManager.AddScreen(new MainMenuScreen());
- // hookup the invite event-processing function
- NetworkSession.InviteAccepted += new EventHandler<InviteAcceptedEventArgs>(NetworkSession_InviteAccepted);
- }
- /// <summary>
- /// Begins the asynchronous process of joining a game from an invitation.
- /// </summary>
- void NetworkSession_InviteAccepted(object sender, InviteAcceptedEventArgs e)
- {
- if (Guide.IsTrialMode)
- {
- screenManager.invited = e.Gamer;
- string message = "Need to unlock full version before you can accept this invite.";
- MessageBoxScreen messageBox = new MessageBoxScreen(message);
- screenManager.AddScreen(messageBox);
- System.Console.WriteLine("Cannot accept invite yet because we're in trial mode");
- return;
- }
- // We will join the game from a method in this screen.
- MainMenuScreen mainMenu = null;
- // Keep the background screen and main menu screen but remove all others
- // to prepare for joining the game we were invited to.
- foreach (GameScreen screen in screenManager.GetScreens())
- {
- if (screen is BackgroundScreen)
- {
- continue;
- }
- else if (screen is MainMenuScreen)
- {
- mainMenu = screen as MainMenuScreen;
- }
- else
- {
- // If there's an active network session, we'll need to end it
- // before attempting to join a new one.
- MethodInfo method = screen.GetType().GetMethod("EndSession");
- if (method != null)
- {
- method.Invoke(screen, null);
- }
- // Now exit and remove this screen.
- screen.ExitScreen();
- screenManager.RemoveScreen(screen);
- }
- }
- // Now attempt to join the game to which we were invited!
- if (mainMenu != null)
- mainMenu.JoinInvitedGame();
- }
- #endregion
- #region Drawing Methods
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
- base.Draw(gameTime);
- }
- #endregion
- #region Entry Point
- // /// <summary>
- // /// The main entry point for the application.
- // /// </summary>
- // static class Program
- // {
- // static void Main()
- // {
- // using (NetRumbleGame game = new NetRumbleGame())
- // {
- // game.Run();
- // }
- // }
- // }
- #endregion
- }
- }
|