예제 #1
0
        public bool canAdvance()
        {
            KeyboardState kb = Keyboard.GetState();
            MouseState    ms = Mouse.GetState();
            GamePadState  gp = GamePad.GetState(PlayerIndex.One);

            KeyboardState okb = OldKeyboard.GetState();
            MouseState    oms = OldMouse.GetState();
            GamePadState  ogp = OldGamePad.GetState();

            return(
                ((kb.IsKeyDown(Keys.Escape) && !okb.IsKeyDown(Keys.Escape)) ||
                 (kb.IsKeyDown(Keys.Space) && !okb.IsKeyDown(Keys.Space)) ||
                 ((ms.LeftButton != ButtonState.Pressed &&
                   ms.X >= 0 && ms.Y >= 0 && ms.X < ScreenSize.X && ms.Y < ScreenSize.Y &&
                   oms.LeftButton == ButtonState.Pressed))

                 || (gp.Buttons.Start == ButtonState.Pressed && ogp.Buttons.Start != ButtonState.Pressed) ||
                 (gp.Buttons.A == ButtonState.Pressed && ogp.Buttons.A != ButtonState.Pressed) ||
                 (gp.Buttons.B == ButtonState.Pressed && ogp.Buttons.B != ButtonState.Pressed) ||
                 ((kb.IsKeyDown(Keys.Enter) && !kb.IsKeyDown(Keys.LeftAlt) && !kb.IsKeyDown(Keys.RightAlt)) &&
                  !(okb.IsKeyDown(Keys.Enter) && !okb.IsKeyDown(Keys.LeftAlt) && !okb.IsKeyDown(Keys.RightAlt))
                 )
                )
                );
        }
예제 #2
0
 private void up()
 {
     // Update controls.
     KeyboardState keyState    = Keyboard.GetState();
     KeyboardState oldkeyState = OldKeyboard.GetState();
     GamePadState  padState    = GamePad.GetState(PlayerIndex.One);
     GamePadState  oldpadState = OldGamePad.GetState();
 }
예제 #3
0
        public override void Update(float elapsedTime)
        {
            if ((Keyboard.GetState().IsKeyDown(Keys.Down) && !OldKeyboard.GetState().IsKeyDown(Keys.Down)) ||
                (Keyboard.GetState().IsKeyDown(Keys.S) && !OldKeyboard.GetState().IsKeyDown(Keys.S)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.DPadDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.DPadDown)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.LeftThumbstickDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.LeftThumbstickDown)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.RightThumbstickDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.RightThumbstickDown))
                )
            {
                unSelectCurrentButton();
                selectButton(currentButton.nextButton);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up) && !OldKeyboard.GetState().IsKeyDown(Keys.Up) ||
                (Keyboard.GetState().IsKeyDown(Keys.W) && !OldKeyboard.GetState().IsKeyDown(Keys.W)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.DPadUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.DPadUp)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.LeftThumbstickUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.LeftThumbstickUp)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.RightThumbstickUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.RightThumbstickUp))

                )
            {
                unSelectCurrentButton();
                selectButton(currentButton.prevButton);
            }

            if (!(Keyboard.GetState().IsKeyDown(Keys.RightAlt) || Keyboard.GetState().IsKeyDown(Keys.LeftAlt)))
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter) && !OldKeyboard.GetState().IsKeyDown(Keys.Enter) ||
                    GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.A) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.A))
                {
                    currentButton.isPressed = true;
                    buttonPressed           = true;
                }
                if (Keyboard.GetState().IsKeyUp(Keys.Enter) && !OldKeyboard.GetState().IsKeyUp(Keys.Enter) ||
                    GamePad.GetState(PlayerIndex.One).IsButtonUp(Input.Buttons.A) && !OldGamePad.GetState().IsButtonUp(Input.Buttons.A))
                {
                    if (currentButton.isPressed)
                    {
                        currentButton.DispatchOnMouseUp(true);
                    }
                }
            }

            base.Update(elapsedTime);
        }
예제 #4
0
        public override void Update(float elapsedTime)
        {
            //Scaling
            float scaleX = ScreenSize.X / menuBackground.Texture.Width;
            float scaleY = ScreenSize.Y / menuBackground.Texture.Height;

            if (scaleX < scaleY)
            {
                ScreenScale  = new Vector2(1.0f, scaleX / scaleY);
                ScreenOffset = new Vector2(0.0f, (ScreenSize.Y - ScreenScale.Y * ScreenSize.Y) / 2);
            }
            else
            {
                ScreenScale  = new Vector2(scaleY / scaleX, 1.0f);
                ScreenOffset = new Vector2((ScreenSize.X - ScreenScale.X * ScreenSize.X) / 2, 1.0f);
            }

            float scale = Math.Min(scaleX, scaleY);

            menuBackground.Scale    = scale;
            playButton.Scale        = scale;
            instructionButton.Scale = scale;
            creditsButton.Scale     = scale;
            quitButton.Scale        = scale;

            if ((Keyboard.GetState().IsKeyDown(Keys.Down) && !OldKeyboard.GetState().IsKeyDown(Keys.Down)) ||
                (Keyboard.GetState().IsKeyDown(Keys.S) && !OldKeyboard.GetState().IsKeyDown(Keys.S)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.DPadDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.DPadDown)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.LeftThumbstickDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.LeftThumbstickDown)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.RightThumbstickDown) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.RightThumbstickDown))
                )
            {
                unSelectCurrentButton();
                selectButton(currentButton.nextButton);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up) && !OldKeyboard.GetState().IsKeyDown(Keys.Up) ||
                Keyboard.GetState().IsKeyDown(Keys.W) && !OldKeyboard.GetState().IsKeyDown(Keys.W) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.DPadUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.DPadUp)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.LeftThumbstickUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.LeftThumbstickUp)) ||
                (GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.RightThumbstickUp) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.RightThumbstickUp))
                )
            {
                unSelectCurrentButton();
                selectButton(currentButton.prevButton);
            }

            if (!(Keyboard.GetState().IsKeyDown(Keys.RightAlt) || Keyboard.GetState().IsKeyDown(Keys.LeftAlt)))
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter) && !OldKeyboard.GetState().IsKeyDown(Keys.Enter) ||
                    GamePad.GetState(PlayerIndex.One).IsButtonDown(Input.Buttons.A) && !OldGamePad.GetState().IsButtonDown(Input.Buttons.A))
                {
                    currentButton.isPressed = true;
                }
                if (Keyboard.GetState().IsKeyUp(Keys.Enter) && !OldKeyboard.GetState().IsKeyUp(Keys.Enter) ||
                    GamePad.GetState(PlayerIndex.One).IsButtonUp(Input.Buttons.A) && !OldGamePad.GetState().IsButtonUp(Input.Buttons.A))
                {
                    if (currentButton.isPressed)
                    {
                        currentButton.DispatchOnMouseUp(true);
                    }
                }
            }

            Fader.Update(elapsedTime);

            base.Update(elapsedTime);
        }
예제 #5
0
        protected void OnUpdate()
        {
            ActionsFired.Clear();
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            foreach (KeyValuePair <InputActions, InputState> action in Inputs.Info)
            {
                // Manage mouse events.
                if (!action.Value.IsKeyboard && action.Value.MouseKey != MouseKeys.None)
                {
                    if (CheckMouseState(keyboardState, mouseState, action.Value))
                    {
                        if (InputEvents.ContainsKey(action.Key))
                        {
                            InputEvents[action.Key](this, new InputEventArgs()
                            {
                                MousePosition = MousePosition
                            });
                        }
                        ActionsFired.Add(action.Key);
                    }
                }
                else if (action.Value.KeyboardKey != Keys.None)
                {
                    switch (action.Value.State)
                    {
                    // The type of key state.
                    case KeyState.Up:
                        // Makes sure it is in the good state.
                        if (keyboardState.IsKeyUp(action.Value.KeyboardKey) && (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            // Adds it to the list to be able to query all event fired in this frame.
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Down:
                        if (keyboardState.IsKeyDown(action.Value.KeyboardKey) && (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Pressed:
                        if (keyboardState.IsKeyDown(action.Value.KeyboardKey) && OldKeyboard.IsKeyUp(action.Value.KeyboardKey) &&
                            (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Released:
                        if (keyboardState.IsKeyUp(action.Value.KeyboardKey) && OldKeyboard.IsKeyDown(action.Value.KeyboardKey) &&
                            (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;
                    }
                }
            }
            OldKeyboard = keyboardState;
            OldMouse    = mouseState;

            if (IsWindowReady && IsActive)
            {
                Cursor.Position = MousePosition;
            }
        }
예제 #6
0
        private void ProcessControls(out int dirX, out int dirY)
        {
            KeyboardState keyState    = Keyboard.GetState();
            KeyboardState oldKeyState = OldKeyboard.GetState();
            GamePadState  padState    = GamePad.GetState(PlayerIndex.One);
            GamePadState  oldpadState = OldGamePad.GetState();

            dirX = 0;
            dirY = 0;

            if (enableUp && (keyState.IsKeyDown(Keys.Up) ||
                             keyState.IsKeyDown(Keys.W) ||
                             padState.IsButtonDown(Buttons.DPadUp) ||
                             padState.ThumbSticks.Left.Y > threshold ||
                             padState.ThumbSticks.Right.Y > threshold
                             ))
            {
                --dirY;
            }

            if ((enableDown && (keyState.IsKeyDown(Keys.Down) ||
                                keyState.IsKeyDown(Keys.S) ||
                                padState.IsButtonDown(Buttons.DPadDown) ||
                                padState.ThumbSticks.Left.Y < -threshold ||
                                padState.ThumbSticks.Right.Y < -threshold
                                )) || endingDescent)
            {
                ++dirY;
            }

            if (enableLeft && (keyState.IsKeyDown(Keys.Left) ||
                               keyState.IsKeyDown(Keys.A) ||
                               padState.IsButtonDown(Buttons.DPadLeft) ||
                               padState.ThumbSticks.Left.X < -threshold ||
                               padState.ThumbSticks.Right.X < -threshold
                               ))
            {
                Environment.Camera.EffectScale = 1.0f + 2 * zoomAmount;
                --dirX;
            }

            if ((enableRight && (keyState.IsKeyDown(Keys.Right) ||
                                 keyState.IsKeyDown(Keys.D) ||
                                 padState.IsButtonDown(Buttons.DPadRight) ||
                                 padState.ThumbSticks.Left.X > threshold ||
                                 padState.ThumbSticks.Right.X > threshold
                                 )) || endingDescent)
            {
                Environment.Camera.EffectScale = 1.0f;
                ++dirX;
            }
            if (!keyState.IsKeyDown(Keys.Right) && !keyState.IsKeyDown(Keys.Left))
            {
                Environment.Camera.EffectScale = 1.0f + zoomAmount;
            }
            if (dirY == -1 && dirY != lastDirY)
            {
                upSound = Sound.PlayCue("up");
            }
            if (dirY == 1 && dirY != lastDirY)
            {
                downSound = Sound.PlayCue("down");
            }

            // Events on key down.
            if (dirX == -1 && dirX != lastDirX)
            {
                leftSound = Sound.PlayCue("left");
                Environment.OnPressureChange(1.0f);
            }
            if (dirX == 1 && dirX != lastDirX)
            {
                rightSound = Sound.PlayCue("right");
                Environment.OnPressureChange(-1.0f);
            }

            if (downSound != null && dirY != 1)
            {
                downSound.Stop(AudioStopOptions.AsAuthored);
                downSound = null;
            }
            if (upSound != null && dirY != -1)
            {
                upSound.Stop(AudioStopOptions.AsAuthored);
                upSound = null;
            }
            if (leftSound != null && dirX != -1)
            {
                leftSound.Stop(AudioStopOptions.AsAuthored);
                leftSound = null;
                Environment.OnPressureChange(0.0f);
            }
            if (rightSound != null && dirX != 1)
            {
                rightSound.Stop(AudioStopOptions.AsAuthored);
                rightSound = null;
                Environment.OnPressureChange(0.0f);
            }
        }