示例#1
0
        protected override void LoadContent()
        {
            FileIOSystem.LoadGameSettings(ref this._gameSettings);
            this.IsMouseVisible                           = false;
            this.Window.AllowUserResizing                 = false;
            this.Window.IsBorderless                      = this._gameSettings.Borderless;
            this._graphics.PreferredBackBufferWidth       = (int)this._gameSettings.Resolution.X;
            this._graphics.PreferredBackBufferHeight      = (int)this._gameSettings.Resolution.Y;
            this._graphics.SynchronizeWithVerticalRetrace = this._gameSettings.Vsync;
            this.IsFixedTimeStep                          = this._gameSettings.Vsync;
            this._graphics.ApplyChanges();


            this._camera       = new Camera(GraphicsDevice.Viewport, GraphicsDevice.Viewport.Bounds.Center.ToVector2(), 0f, 1f);
            this._spriteBatch  = new SpriteBatch(GraphicsDevice);
            this._debugText    = Content.Load <SpriteFont>(DevConstants.FontAssets.Debug);
            this._currentState = new TitleState(Content);
        }
示例#2
0
        public ILevel Update(GameTime gameTime, Camera camera, ref GameSettings gameSettings, KeyboardState currentKey, KeyboardState prevKey, MouseState currentMouse, MouseState prevMouse)
        {
            if (currentKey.IsKeyDown(Keys.Escape) && prevKey.IsKeyUp(Keys.Escape))
            {
                return(null);
            }

            if (currentKey.IsKeyDown(Keys.Up) && prevKey.IsKeyUp(Keys.Up))
            {
                _selectedOption -= 1;
                if (_selectedOption < 0)
                {
                    _selectedOption = Enum.GetNames(typeof(Options)).Length - 1;
                }
                if (_selectedOption > Enum.GetNames(typeof(Options)).Length - 1)
                {
                    _selectedOption = 0;
                }
            }

            if (currentKey.IsKeyDown(Keys.Down) && prevKey.IsKeyUp(Keys.Down))
            {
                _selectedOption += 1;
                if (_selectedOption < 0)
                {
                    _selectedOption = Enum.GetNames(typeof(Options)).Length - 1;
                }
                if (_selectedOption > Enum.GetNames(typeof(Options)).Length - 1)
                {
                    _selectedOption = 0;
                }
            }


            if (currentKey.IsKeyDown(Keys.Left) && prevKey.IsKeyUp(Keys.Left) && _optionItems[_selectedOption].OptionsCollection != null)
            {
                _optionItems[_selectedOption].Selection -= 1;
                if (_optionItems[_selectedOption].Selection < 0)
                {
                    _optionItems[_selectedOption].Selection = _optionItems[_selectedOption].OptionsCollection.Count - 1;
                }
                if (_optionItems[_selectedOption].Selection >= _optionItems[_selectedOption].OptionsCollection.Count)
                {
                    _optionItems[_selectedOption].Selection = 0;
                }
            }

            if (currentKey.IsKeyDown(Keys.Right) && prevKey.IsKeyUp(Keys.Right) && _optionItems[_selectedOption].OptionsCollection != null)
            {
                _optionItems[_selectedOption].Selection += 1;
                if (_optionItems[_selectedOption].Selection < 0)
                {
                    _optionItems[_selectedOption].Selection = _optionItems[_selectedOption].OptionsCollection.Count - 1;
                }
                if (_optionItems[_selectedOption].Selection >= _optionItems[_selectedOption].OptionsCollection.Count)
                {
                    _optionItems[_selectedOption].Selection = 0;
                }
            }

            if (currentKey.IsKeyDown(Keys.Enter) && prevKey.IsKeyUp(Keys.Enter))
            {
                switch (_selectedOption)
                {
                case (int)Options.ACCEPT_CHANGES:
                    this._gameSettings.Resolution = (Vector2)_optionItems[(int)Options.RESOLUTION].OptionsCollection[_optionItems[(int)Options.RESOLUTION].Selection];
                    this._gameSettings.Borderless = (bool)_optionItems[(int)Options.BORDERLESS_WINDOW].OptionsCollection[_optionItems[(int)Options.BORDERLESS_WINDOW].Selection];
                    this._gameSettings.Vsync      = (bool)_optionItems[(int)Options.VSYNC].OptionsCollection[_optionItems[(int)Options.VSYNC].Selection];
                    FileIOSystem.SaveGameSettings(ref this._gameSettings);
                    return(null);

                case (int)Options.DEFAULT_SETTINGS:
                    FileIOSystem.ResetGameSettings();
                    FileIOSystem.LoadGameSettings(ref gameSettings);
                    return(new GameSettingsLevel(ref gameSettings));

                case (int)Options.CANCEL:
                    return(null);
                }
            }

            return(this);
        }