public static void Initialize(Level[] levels, SpriteFont f, Dock d, IInputManager man)
 {
     Manager = man;
     levelArray = levels;
     PreviousState = GameState.MainMenu;
     State = GameState.MainMenu;
     font = f;
     dock = d;
 }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            #if INDIECITY
            if(error)
            {
                SuppressDraw();
                return;
            }

            Session.UpdateSession();
            if(!Session.IsSessionStarted() && request)
            {
                request = false;
                Session.RequestStartSession();
            }
            else if(Session.IsSessionStarted() && !request)
                request = true;
            #endif
            if(LoadingScreen == null && Loader == null) // do once and only once (or when we need to reload)
            {
                Box.Initialize(this);
                RenderingDevice.Initialize(GDM, Program.Cutter, GameManager.Space, Content.Load<Effect>("Shaders/shadowmap"), Content.Load<Texture2D>("textures/lightMap"));

                LoadingScreen = new LoadingScreen(Content, GraphicsDevice);

                backgroundTex = Content.Load<Texture2D>("2D/Splashes and Overlays/Logo");

                Extensions.Initialize(GraphicsDevice);
                Resources.Initialize(Content);
            #if WINDOWS
                Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(SystemEvents_SessionSwitch);
                GDM.DeviceCreated += onGDMCreation;
            #endif
            }

            if(stateLastFrame == GameState.Running && GameManager.State == GameState.Paused)
                MediaSystem.PlaySoundEffect(SFXOptions.Pause);

            stateLastFrame = GameManager.State;

            if((!IsActive && Loader != null) || locked)
            {
                base.Update(gameTime);
                return;
            }

            Input.Update(gameTime, MenuHandler.IsSelectingSave);
            MediaSystem.Update(gameTime, Program.Game.IsActive);

            if(Manager.SaveLoaded)
                AccomplishmentManager.Update(gameTime);

            if(LoadingScreen != null)
            {
                if(alpha + 3 >= 255)
                {
                    alpha = 255;
                    readyToLoad = true;
                    if(subFactor - 3 < 0)
                        subFactor = 0;
                    else
                        subFactor -= 3;
                }
                else
                    alpha += 3;

                IsMouseVisible = false;

                if(readyToLoad)
                {
                    Loading = true;
                    IsFixedTimeStep = false;

                    Loader = LoadingScreen.Update(gameTime);
                    if(Loader != null)
                    {
                        // Content loaded.  Use loader members to get at the loaded content.
                        LoadingScreen = null;
                        IsFixedTimeStep = true; // Back to the default -- change if you want.
                        Loading = false;
                        Dock = new Dock(delegate { return Loader.Dock; }, delegate { return Loader.Font; });
                        MenuHandler.Create(Loader);
                        GameManager.Initialize(Loader.levelArray, Loader.Font, Dock, Manager);
            #if INDIECITY
                        AccomplishmentManager.Ready(Session, UserInfo.GetId());
            #else
                        AccomplishmentManager.Ready();
            #endif
                        MediaSystem.PlayVoiceActing(12);
                        BlackBox.Initialize(Content.Load<Effect>("Shaders/bbeffect"), Loader.blackBoxBillboardList);
                    }
                }
            }
            else
            {
                //if(State != GameState.Ending)
                //{
                //    MediaSystem.PlayTrack(SongOptions.Credits);
                //    State = GameState.Ending;
                //}

                if(GameManager.State == GameState.MainMenu && Loading)
                    this.IsMouseVisible = false;
                else
                    this.IsMouseVisible = true;

                GameState statePrior = GameManager.State;
                MenuHandler.Update(gameTime);
                bool stateChanged = GameManager.State != statePrior;

                #region Running
                if(GameManager.State == GameState.Running)
                {
                    if(((Input.CheckKeyboardJustPressed(Program.Game.Manager.CurrentSaveWindowsOptions.PauseKey) ||
                        Input.CheckXboxJustPressed(Manager.CurrentSaveXboxOptions.PauseKey)) && !GameManager.CurrentLevel.ShowingOverlay &&
                        !GameManager.CurrentLevel.Ending) && !stateChanged)
                    {
                        //MediaSystem.PlaySoundEffect(SFXOptions.Pause);
                        GameManager.State = GameState.Paused;
                    }
            #if DEBUG
                    else if(Input.CheckKeyboardJustPressed(Program.Game.Manager.CurrentSaveWindowsOptions.HelpKey) ||
                        Input.CheckXboxJustPressed(Manager.CurrentSaveXboxOptions.HelpKey) && GameManager.CurrentLevel.spawnlevel == 0)
            #else
                    else if(Input.CheckKeyboardJustPressed(Program.Game.Manager.CurrentSaveWindowsOptions.HelpKey) ||
                        Input.CheckXboxJustPressed(Manager.CurrentSaveXboxOptions.HelpKey))
            #endif
                    {
                        renderDock = !renderDock;
                        if(renderDock)
                            Dock.Open();
                        else
                            Dock.Close();
                    }
                    else
                    {
                        Manager.CurrentSave.Playtime += gameTime.ElapsedGameTime;
                        GameManager.Space.Update((float)(gameTime.ElapsedGameTime.TotalSeconds));
            #if DEBUG
                        if(Input.KeyboardState.IsKeyDown(Keys.Q))
                            GameManager.Space.Update((float)(gameTime.ElapsedGameTime.TotalSeconds));
            #endif
                        RenderingDevice.Update(gameTime);
                        if(GameManager.CurrentLevel != null)
                            GameManager.CurrentLevel.Update(gameTime);
                    }
                }
                #endregion

                if(GameManager.State == GameState.Results)
                {
                    GameManager.Space.Update((float)(gameTime.ElapsedGameTime.TotalSeconds));
                    GameManager.CurrentLevel.Update(gameTime);
                    RenderingDevice.Update(gameTime);
                }
            }

            base.Update(gameTime);
        }