Esempio n. 1
0
        private void LoadLevel()
        {
            int levelID = GameSettings.Instance.CurrentLevel;

            if (this._level != null)
            {
                this._level.Content.Unload();
            }

            this._level = new Level();
            this._world = new World(Vector2.Zero);
            //Camera.Instance.SetUpIs(UpIs.Up);
            EventManager.Instance.Load(this);
            SpriteManager.Instance.Clear();
            HUD.Instance.RefreshHUD();

            AudioManager.Instance.StopAllSounds(AudioStopOptions.AsAuthored);
            this.PlayRandomAmbience();

            try
            {
                using (XmlReader reader = XmlReader.Create(Defines.Level(levelID)))
                {
                    this._level = IntermediateSerializer.Deserialize <Level>(reader, null);
                }
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show("Something went wrong when trying to load level: '" + levelID + "'\nThe level wasn't found.");
                ErrorReport.GenerateReport("The level " + levelID + " could not be found.\n" + e.ToString(), null);
                ScreenManager.Game.Exit();
            }

            try
            {
                this._level.Load(this);
            }
            catch (ContentLoadException e)
            {
                string error = e.InnerException.ToString();

                MessageBox.Show("Something went wrong loading level " + levelID + ".\n" + error);
                ErrorReport.GenerateReport(error, null);
            }

            //  Now the level has been set up, if we have development
            //  mode on, turn on the display.
            if (GameSettings.Instance.DevelopmentMode)
            {
                DevDisplay.Load(this.ScreenManager, World);
            }
        }