Exemple #1
0
        public Game()
        {
            graphics = new GraphicsDeviceManager(this);
            // Initialises the Resolution class, allowing the game to auto-scale all assets based on the resolution.
            Resolution.Init(ref graphics);
            Content.RootDirectory = "Content";

            // Sets up the path to the content folder based on the .exe local location
            _index = Assembly.GetExecutingAssembly().Location.LastIndexOf("\\");
            _path = Assembly.GetExecutingAssembly().Location.Substring(0, _index);

            // Loads the Application Settings XML file
            System.Xml.XmlDocument appConfigXML = new System.Xml.XmlDocument();
            System.Xml.XmlDocument serConfigXML = new System.Xml.XmlDocument();
            appConfigXML.Load(Game._path + "\\Content\\ApplicationSettings.xml");
            serConfigXML.Load(Game._path + "\\Content\\ServiceSettings.xml");

            // Sets the application settings based on the values of the XML file.
            // Some of the values have to be converted to a different type as when they are read
            // they are all read in as Strings. Of course this then doesn't match the intended type.
            Window.Title = appConfigXML.SelectSingleNode("//ScreenTitle").InnerText;
            this.IsMouseVisible = Convert.ToBoolean(appConfigXML.SelectSingleNode("//MouseActive").InnerText);
            int selectedResolutionWidth = Convert.ToInt16(appConfigXML.SelectSingleNode("//ScreenWidth").InnerText);
            int selectedResolutionHeight = Convert.ToInt16(appConfigXML.SelectSingleNode("//ScreenHeight").InnerText);
            bool selectedFullScreen = Convert.ToBoolean(appConfigXML.SelectSingleNode("//FullScreen").InnerText);

            // Change Virtual Resolution
            Resolution.SetVirtualResolution(1280, 720); // This is the default resolution.. do not change this or you'll break everything!
            Resolution.SetResolution(selectedResolutionWidth, selectedResolutionHeight, selectedFullScreen);

            // Loads the screenmanager
            // Ideally we would want all of our stuff to plug in like this. i.e.
            // Components.Add(userManager); Components.Add(resourceManager); Components.Add(physicsManager); etc
            screenManager = new ScreenManager(this);
            inputManager = new InputManager();
            Components.Add(screenManager);
        }