Ejemplo n.º 1
0
        public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings)
        {
            IState nextState = this;
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Escape) && PrevKeyboardState.IsKeyUp(Keys.Escape))
            {
                nextState = previousState;
                nextState.SetPrevInput(Keyboard.GetState(), Mouse.GetState(), GamePad.GetState(PlayerIndex.One));
            }
            else if (keyState.IsKeyDown(Keys.Up) && PrevKeyboardState.IsKeyUp(Keys.Up))
            {
                optionSelection -= 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
                while (!menuOptions[optionSelection].Enabled)
                {
                    optionSelection -= 1;
                }
            }
            else if (keyState.IsKeyDown(Keys.Down) && PrevKeyboardState.IsKeyUp(Keys.Down))
            {
                optionSelection += 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
                while (!menuOptions[optionSelection].Enabled)
                {
                    optionSelection += 1;
                }
            }

            else if (keyState.IsKeyDown(Keys.Enter) && PrevKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (optionSelection)
                {
                    case (int)Options.OPTIONS:
                        GameSettingsMenuStateSpace nextStateSpace = new GameSettingsMenuStateSpace(ref gameSettings);
                        nextState = new MenuState(nextStateSpace, camera, Content, Graphics, this, keyboardState: Keyboard.GetState());
                        break;
                    case (int)Options.SAVE_TITLE:
                        FileIO.SaveDungeonData(((PlayingState)previousState).GetSaveData());
                        nextState = new TitleState(camera, Content, Graphics, Mouse.GetState(), GamePad.GetState(PlayerIndex.One), keyState);
                        break;
                    case (int)Options.UNPAUSE:
                        nextState = previousState;
                        nextState.SetPrevInput(Keyboard.GetState(), Mouse.GetState(), GamePad.GetState(PlayerIndex.One));
                        break;
                }
            }

            PrevKeyboardState = Keyboard.GetState();
            PrevMouseState = Mouse.GetState();
            PrevGamepadState = GamePad.GetState(PlayerIndex.One);
            return nextState;
        }
        public IStateSpace UpdateSpace(GameTime gameTime, ContentManager content, GraphicsDeviceManager graphics, KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera, ref GameSettings gameSettings)
        {
            IStateSpace   nextSpace = this;
            KeyboardState keyState  = Keyboard.GetState();

            if (keyState.IsKeyDown(Keys.Escape) && prevKeyboardState.IsKeyUp(Keys.Escape))
            {
                nextSpace = null;
            }
            else if (keyState.IsKeyDown(Keys.Up) && prevKeyboardState.IsKeyUp(Keys.Up))
            {
                optionSelection -= 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Down) && prevKeyboardState.IsKeyUp(Keys.Down))
            {
                optionSelection += 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Left) && prevKeyboardState.IsKeyUp(Keys.Left) && menuOptions[optionSelection].OptionsCollection != null)
            {
                menuOptions[optionSelection].Selection -= 1;
                if (menuOptions[optionSelection].Selection < 0)
                {
                    menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1;
                }
                if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count)
                {
                    menuOptions[optionSelection].Selection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Right) && prevKeyboardState.IsKeyUp(Keys.Right) && menuOptions[optionSelection].OptionsCollection != null)
            {
                menuOptions[optionSelection].Selection += 1;
                if (menuOptions[optionSelection].Selection < 0)
                {
                    menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1;
                }
                if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count)
                {
                    menuOptions[optionSelection].Selection = 0;
                }
            }

            else if (keyState.IsKeyDown(Keys.Enter) && prevKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (optionSelection)
                {
                case (int)Options.SAVE_CHANGES:
                    gameSettings.Resolution = (Vector2)menuOptions[(int)Options.RESOLUTION].OptionsCollection[menuOptions[(int)Options.RESOLUTION].Selection];
                    gameSettings.Scale      = (float)menuOptions[(int)Options.GRAPHICS_SCALE].OptionsCollection[menuOptions[(int)Options.GRAPHICS_SCALE].Selection];
                    gameSettings.Borderless = (bool)menuOptions[(int)Options.BORDERLESS].OptionsCollection[menuOptions[(int)Options.BORDERLESS].Selection];
                    gameSettings.ShowGlow   = (bool)menuOptions[(int)Options.GLOW_FILTER].OptionsCollection[menuOptions[(int)Options.GLOW_FILTER].Selection];
                    gameSettings.Vsync      = (bool)menuOptions[(int)Options.VSYNC].OptionsCollection[menuOptions[(int)Options.VSYNC].Selection];
                    FileIO.SaveGameSettings(ref gameSettings);
                    nextSpace = null;
                    break;

                case (int)Options.RESTORE_DEFAULTS:
                    FileIO.ResetGameSettings();
                    FileIO.LoadGameSettings(ref gameSettings);
                    nextSpace = new GameSettingsMenuStateSpace(ref gameSettings);
                    break;

                case (int)Options.CANCEL:
                    nextSpace = null;
                    break;
                }
            }

            return(nextSpace);
        }
        public IStateSpace UpdateSpace(GameTime gameTime, ContentManager content, GraphicsDeviceManager graphics, KeyboardState prevKeyboardState, MouseState prevMouseState, GamePadState prevGamepadState, Camera camera, ref GameSettings gameSettings)
        {
            IStateSpace nextSpace = this;
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Escape) && prevKeyboardState.IsKeyUp(Keys.Escape))
            {
                nextSpace = null;
            }
            else if (keyState.IsKeyDown(Keys.Up) && prevKeyboardState.IsKeyUp(Keys.Up))
            {
                optionSelection -= 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Down) && prevKeyboardState.IsKeyUp(Keys.Down))
            {
                optionSelection += 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Left) && prevKeyboardState.IsKeyUp(Keys.Left) && menuOptions[optionSelection].OptionsCollection != null)
            {
                menuOptions[optionSelection].Selection -= 1;
                if (menuOptions[optionSelection].Selection < 0)
                {
                    menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1;
                }
                if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count)
                {
                    menuOptions[optionSelection].Selection = 0;
                }
            }
            else if (keyState.IsKeyDown(Keys.Right) && prevKeyboardState.IsKeyUp(Keys.Right) && menuOptions[optionSelection].OptionsCollection != null)
            {
                menuOptions[optionSelection].Selection += 1;
                if (menuOptions[optionSelection].Selection < 0)
                {
                    menuOptions[optionSelection].Selection = menuOptions[optionSelection].OptionsCollection.Count - 1;
                }
                if (menuOptions[optionSelection].Selection >= menuOptions[optionSelection].OptionsCollection.Count)
                {
                    menuOptions[optionSelection].Selection = 0;
                }
            }

            else if (keyState.IsKeyDown(Keys.Enter) && prevKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (optionSelection)
                {
                    case (int)Options.SAVE_CHANGES:
                        gameSettings.Resolution = (Vector2)menuOptions[(int)Options.RESOLUTION].OptionsCollection[menuOptions[(int)Options.RESOLUTION].Selection];
                        gameSettings.Scale = (float)menuOptions[(int)Options.GRAPHICS_SCALE].OptionsCollection[menuOptions[(int)Options.GRAPHICS_SCALE].Selection];
                        gameSettings.Borderless = (bool)menuOptions[(int)Options.BORDERLESS].OptionsCollection[menuOptions[(int)Options.BORDERLESS].Selection];
                        gameSettings.ShowGlow = (bool)menuOptions[(int)Options.GLOW_FILTER].OptionsCollection[menuOptions[(int)Options.GLOW_FILTER].Selection];
                        gameSettings.Vsync = (bool)menuOptions[(int)Options.VSYNC].OptionsCollection[menuOptions[(int)Options.VSYNC].Selection];
                        FileIO.SaveGameSettings(ref gameSettings);
                        nextSpace = null;
                        break;
                    case (int)Options.RESTORE_DEFAULTS:
                        FileIO.ResetGameSettings();
                        FileIO.LoadGameSettings(ref gameSettings);
                        nextSpace = new GameSettingsMenuStateSpace(ref gameSettings);
                        break;
                    case (int)Options.CANCEL:
                        nextSpace = null;
                        break;
                }
            }

            return nextSpace;
        }
Ejemplo n.º 4
0
        public IState UpdateContent(GameTime gameTime, Camera camera, ref GameSettings gameSettings)
        {
            camera.Position = Vector2.Zero;
            camera.Target = Vector2.Zero;
            IState nextState = this;
            KeyboardState keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Up) && PrevKeyboardState.IsKeyUp(Keys.Up))
            {
                optionSelection -= 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
                while (!menuOptions[optionSelection].Enabled)
                {
                    optionSelection -= 1;
                }
            }
            else if (keyState.IsKeyDown(Keys.Down) && PrevKeyboardState.IsKeyUp(Keys.Down))
            {
                optionSelection += 1;
                if (optionSelection < 0)
                {
                    optionSelection = optionsAmount - 1;
                }
                if (optionSelection >= optionsAmount)
                {
                    optionSelection = 0;
                }
                while (!menuOptions[optionSelection].Enabled)
                {
                    optionSelection += 1;
                }
            }

            else if (keyState.IsKeyDown(Keys.Enter) && PrevKeyboardState.IsKeyUp(Keys.Enter))
            {
                switch (optionSelection)
                {
                    case (int)Options.NEW_GAME:
                        RandomlyGeneratedStateSpace nextStateSpace = new RandomlyGeneratedStateSpace(new CaveGeneration(), 75, 125);
                        nextState = new PlayingState(nextStateSpace, camera, Content, Graphics, this, keyboardState: keyState);
                        break;
                    case (int)Options.LOAD_GAME:
                        RandomlyGeneratedStateSpace nextSpace = new RandomlyGeneratedStateSpace(DungeonInfo);
                        nextState = new PlayingState(nextSpace, camera, Content, Graphics, saveInfo: DungeonInfo, keyboardState: keyState);
                        break;
                    case (int)Options.OPTIONS:
                        GameSettingsMenuStateSpace nextMenu = new GameSettingsMenuStateSpace(ref gameSettings);
                        nextState = new MenuState(nextMenu, camera, Content, Graphics, this, keyboardState: keyState);
                        break;
                    case (int)Options.QUIT_GAME:
                        nextState = previousState;
                        break;
                }
            }

            PrevKeyboardState = Keyboard.GetState();
            PrevMouseState = Mouse.GetState();
            PrevGamepadState = GamePad.GetState(PlayerIndex.One);
            return nextState;
        }