Esempio n. 1
0
        /// <summary>
        /// Processes keystrokes.
        /// </summary>
        /// <param name="gameTime"></param>
        private void ProcessInput(GameTime gameTime)
        {
            if (_backspaceheld)
            {
                _deleteTimer -= gameTime.ElapsedGameTime;
                if (_deleteTimer <= TimeSpan.Zero)
                {
                    _deleteNextChar = true;
                }
            }

            _currentKeyboardState = Keyboard.GetState();

            if ((_currentKeyboardState.IsKeyDown(Keys.RightShift) ||
                 _currentKeyboardState.IsKeyDown(Keys.LeftShift)) && !_keyShiftTimerStarted)
            {
                _keyShiftTimer = TimeSpan.FromSeconds(0.1);
                _keyShift      = true;
            }

            if (_keyShift)
            {
                _keyShiftTimer -= gameTime.ElapsedGameTime;
                if (_keyShiftTimer <= TimeSpan.Zero)
                {
                    _keyShift             = false;
                    _keyShiftTimerStarted = false;
                }
            }

            if (IsFocused)
            {
                ProcessKeyboard();
            }
        }
        void HandleInput()
        {
            KeyboardState keyboardState = Keyboard.GetState();

            level.Player.HandleInput(keyboardState);

            if (keyboardState.IsKeyDown(Key.Space) || keyboardState.IsKeyDown(Key.Up))
            {
                if (!level.Player.IsAlive)
                {
                    level.StartNewLife();
                }
                else if (level.TimeRemaining == TimeSpan.Zero)
                {
                    if (level.ReachedExit)
                    {
                        LoadNextLevel();
                    }
                    else
                    {
                        ReloadCurrentLevel();
                    }
                }
            }
        }
Esempio n. 3
0
 public override void Update()
 {
     if (warping)
     {
         var state = KB.GetState();
         for (int i = (int)Keys.D1; i < (int)Keys.D9 + 1; i++)
         {
             if (state.IsKeyDown((Keys)i) && !prevState.IsKeyDown((Keys)i))
             {
                 int d = (i - (int)Keys.D0);
                 if (digit == -1)
                 {
                     digit = d;
                 }
                 else
                 {
                     Game.RemoveLevel();
                     Game.AddLevel("Level" + ((digit - 1) * 4 + d));
                     Game.RemoveTransition();
                 }
             }
         }
         prevState = state;
     }
 }
Esempio n. 4
0
 private void RefreshInputState()
 {
     _keyboard = _keyboard.Next(KB.GetState());
     _mouse    = _mouse.Next(MS.GetState());
     UpdateGamePadState(PlayerIndex.One);
     UpdateGamePadState(PlayerIndex.Two);
     UpdateGamePadState(PlayerIndex.Three);
     UpdateGamePadState(PlayerIndex.Four);
 }
    public void Update(GameTime gameTime)
    {
        previousMouseState    = currentMouseState;
        previousKeyboardState = currentKeyboardState;
        previousGamePadState  = (GamePadState[])currentGamePadState.Clone();
        //previousJoyState = currentJoyState;

        currentMouseState    = Mouse.GetState();
        currentKeyboardState = Keyboard.GetState();

        foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex)))
        {
            currentGamePadState[(int)index] = GamePad.GetState(index);
        }

        if (RumbleDuration > 0)
        {
            GamePadVibration(PlayerIndex.One, leftMotor, rightMotor);
            rumbleDuration -= (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        if (!currentGamePadState[0].IsConnected && enableControllers && joystick == null)
        {
            JoystickPing -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (JoystickPing < 0)
            {
                JoystickPing = JoystickPingDuration;
                var th = new Thread(GenericControllerConnection);
                th.Start();
#if DEBUG
                Console.WriteLine("A new thread has been created!");
#endif
            }
        }
        else if (joystick != null && enableControllers)
        {
            joystick.Poll();
#if DEBUG
            Console.WriteLine("Polling Joystick...");
#endif
            try
            {
                JoystickState state = joystick.GetCurrentState();
                currentJoyState = joystick.GetCurrentState();
                bool[] button = state.Buttons;
                int[]  hats   = state.PointOfViewControllers;
                Console.WriteLine("[{0}]", string.Join(", ", hats));
            }
            catch (Exception)
            {
#if DEBUG
                Console.WriteLine("Oops, the controller disconnected!");
#endif
                joystick = null;
            }
        }
    }
Esempio n. 6
0
        protected override void UpdateKeyStates()
        {
            var keyboardState = NativeKeyboard.GetState();

            for (int i = 0; i < (int)Key.NumberOfKeys; i++)
            {
                UpdateKeyState(i, ref keyboardState);
            }
        }
Esempio n. 7
0
 public override void Update(GameTime gameTime)
 {
     CenterScreen = Game.GraphicsDevice.Viewport.Bounds.Center.ToVector2();
     Keyboard     = Keyboard.Next(KB.GetState());
     Mouse        = Mouse.Next(MS.GetState());
     UpdateGamePadState(PlayerIndex.One);
     UpdateGamePadState(PlayerIndex.Two);
     UpdateGamePadState(PlayerIndex.Three);
     UpdateGamePadState(PlayerIndex.Four);
 }
Esempio n. 8
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var kState = XnaKeyboard.GetState();

            for (Int32 i = 0; i < _keyCount; i++)
            {
                this.UpdateKey(_keys[i], ref kState);
            }
        }
Esempio n. 9
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
                ButtonState.Pressed || Keyboard.GetState().IsKeyDown(
                    Keys.Escape))
            {
                Exit();
            }
            base.Update(gameTime);

            _guiGameComponent.Update(gameTime);
        }
Esempio n. 10
0
        public void Update(GameTime gt)
        {
            GamePadState  gs = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            KeyboardState ks = Keyboard.GetState();

            foreach (Keys key in keys.Keys)
            {
                keys[key].Update(ks, gt);
            }
            foreach (Buttons btn in btns.Keys)
            {
                btns[btn].Update(gs, gt);
            }
        }
Esempio n. 11
0
        //=========== UPDATING ===========
        #region Updating

        /** <summary> Called every step to update the key states. </summary> */
        public static void Update(GameTime gameTime)
        {
            // Update each of the keys
            for (int i = 0; i < NumKeys; i++)
            {
                keys[i].Update(1, XnaKeyboard.GetState().IsKeyDown((XnaKeys)i), rawKeyTyped[i]);

                rawKeyTyped[i] = false;
            }

            // Update the typed character
            charTyped    = rawCharTyped;
            rawCharTyped = '\0';
        }
Esempio n. 12
0
        public static void Update(GameTime gameTime)
        {
            if (KeyboardEnabled)
            {
                _input.Update(gameTime);
            }

            _previousMousePosition = new Vector2(Mouse.X, Mouse.Y);
            MousePrevious          = Mouse;
            KeyboardPrevious       = Keyboard;

            Mouse    = XMouse.GetState();
            Keyboard = XKeyboard.GetState();

            _handledKeys.Clear();
            _handledMouseButtons.Clear();
        }
Esempio n. 13
0
        public void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Enter))
            {
                _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
            }

            if (InputManager.KeyPressed(Keys.Z))
            {
                if (_game.Camera.Zoom == 1f)
                {
                    _game.Camera.ZoomTo(5f, 0.5, Position());
                }
                else
                {
                    _game.Camera.ZoomTo(1f, 0.5, Position());
                }
            }

            if (_invincibleTimer.TotalMilliseconds > 0)
            {
                _invincibleTimer -= gameTime.ElapsedGameTime;
            }
            else
            {
                Invincible = false;
            }

            CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds);

            _hitboxSprite.Position = _hitbox.GetCenter();

#if ANDROID
            UpdatePositionFromTouch(gameTime);
            //UpdateAnimationFromTouch();
#else
            UpdatePositionFromKeyboard(gameTime);
            //UpdateAnimationFromKeyboard();
#endif

            CheckOutOfBounds();
            UpdateShoot(gameTime);
        }
        public override void Update(GameTime gameTime)
        {
            _lastState    = _currentState;
            _currentState = XnaKeyboard.GetState();

            // TODO: Map keys to characters.
            foreach (var key in KeyboardHelper.Keys)
            {
                if (IsKeyPressed(key))
                {
                    KeyDown?.Invoke(new KeyboardEventArgs(this, key, '\0'));
                }
                else if (IsKeyReleased(key))
                {
                    KeyUp?.Invoke(new KeyboardEventArgs(this, key, '\0'));
                }
            }
        }
Esempio n. 15
0
        public void Update(GameTime gameTime)
        {
            KeyboardState state = XnaKeyboard.GetState();

            var keysToCheck = new HashSet <Keys>(state.GetPressedKeys());

            keysToCheck.UnionWith(new HashSet <Keys>(prevState.GetPressedKeys()));

            foreach (Keys key in keysToCheck)
            {
                if (state.IsKeyDown(key))
                {
                    OnKeyDown(key, gameTime);
                }
                else if (prevState.IsKeyDown(key))
                {
                    OnKeyUp(key);
                }
            }

            foreach (KeyValuePair <KeyState, HashSet <Keys> > pair in keysByState)
            {
                KeyState       keyState = pair.Key;
                HashSet <Keys> keys     = pair.Value;
                foreach (Keys key in keys)
                {
                    var keyAction = new KeyAction {
                        key   = key,
                        state = keyState
                    };

                    if (keyActionDict.ContainsKey(keyAction))
                    {
                        HashSet <Input> inputs = keyActionDict[keyAction];
                        foreach (Input input in inputs)
                        {
                            inputsReceived.Enqueue(input);
                        }
                    }
                }
            }

            prevState = state;
        }
Esempio n. 16
0
        public void Update(GameTime gameTime)
        {
            _previousKeyboard = _currentKeyboard;
            _currentKeyboard  = Keyboard.GetState();

            _previousMouse = _currentMouse;
            _currentMouse  = Mouse.GetState();

            if (_previousKeyboard.IsKeyDown(ToggleDebugHotKey) && _currentKeyboard.IsKeyUp(ToggleDebugHotKey))
            {
                Enabled = !Enabled;
            }

            if (!Enabled)
            {
                return;
            }
            if (!BoundingBoxesEnabled)
            {
                return;
            }

            if ((_previousMouse.LeftButton == ButtonState.Pressed && _currentMouse.LeftButton != ButtonState.Pressed) ||
                (_previousMouse.RightButton == ButtonState.Pressed && _currentMouse.RightButton != ButtonState.Pressed))
            {
                TopMostFocused = TopMostFocused == null ? _topMostHighlighted : null;
            }

            if (_previousKeyboard.IsKeyDown(Keys.Escape) && _currentKeyboard.IsKeyUp(Keys.Escape))
            {
                TopMostFocused = null;
            }

            // add extra updates below here
            if (TopMostFocused == null)
            {
                CursorPosition = Renderer.Unproject(_currentMouse.Position.ToVector2());
            }

            if (GuiManager.FocusManager.TryGetElementAt(CursorPosition, e => e is GuiElement c,
                                                        out var controlMatchingPosition))
            {
                _topMostHighlighted = controlMatchingPosition as GuiElement;
            }
Esempio n. 17
0
        public static void Update()
        {
            if (Initalized)
            {
                //Build up collection to 5 keyboard states before starting to remove the oldest
                if (states.Count > 5)
                {
                    states.Remove(states[0]);
                }

                states.Add(KeyBoard.GetState());

                current  = states.Count - 1;
                previous = states.Count - 2;
                if (previous < 0)
                {
                    previous = 0;
                }
            }
        }
        private void dx_RenderXna(object sender, GraphicsDeviceEventArgs e)
        {
            if (is_loading || !is_loaded)
            {
                e.Device.Clear(Color.Transparent);
                return;
            }
            //
            KeyboardState s = Keyboard.GetState();

            move_force.X = v(s[Keys.W]) - v(s[Keys.S]);
            move_force.Y = v(s[Keys.A]) - v(s[Keys.D]);
            //
            if (!move_force.Equals(Vector2.Zero))
            {
                scene.Camera.MoveRel(ref move_force);
                scene.Camera.UpdateWorldView();
            }
            //
            scene.Render(e.Device);
        }
Esempio n. 19
0
        public void Update(GameTime gameTime)
        {
            if (_destroyed)
            {
                if (_game.GameManager.TransitioningToEndGame())
                {
                    _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
                    Dispose();
                }

                return;
            }

            if (_game.GameManager.CantMove())
            {
                return;
            }

            if (_ready)
            {
                var keyboardState = Keyboard.GetState();

                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
                }

                if (InputManager.KeyPressed(Keys.Z))
                {
                    if (_game.Camera.Zoom == 1f)
                    {
                        _game.Camera.ZoomTo(5f, 0.5, Position());
                    }
                    else
                    {
                        _game.Camera.ZoomTo(1f, 0.5, Position());
                    }
                }

                if (!_hitTimer.Equals(TimeSpan.Zero))
                {
                    if (_hitTimer.TotalMilliseconds <= 0)
                    {
                        if (_game.SpriteBatchManager.Background != null)
                        {
                            var gradientBackground = (GradientBackground)_game.SpriteBatchManager.Background;
                            gradientBackground.ChangeGradientColors(_savedBackgroundBrightColor,
                                                                    _savedBackgroundDarkColor);

                            _backgroundColorChanged = false;
                        }
                    }
                    else
                    {
                        _hitTimer -= gameTime.ElapsedGameTime;
                    }
                }

#if ANDROID
                UpdatePositionFromTouch(gameTime);
                //UpdateAnimationFromTouch();
#else
                UpdatePositionFromKeyboard(gameTime);
                //UpdateAnimationFromKeyboard();
#endif

                UpdateShoot(gameTime);
                CheckOutOfBounds();
            }

            _hitboxSprite.Position = _hitbox.GetCenter();
            CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds);
        }
Esempio n. 20
0
 protected override bool GetButton(int key)
 {
     return(KB.GetState().IsKeyDown((Keys)key));
 }
Esempio n. 21
0
        public void ProcessKeys(GameTime gameTime)
        {
            this.KeysPressed.Clear();
            this.KeysReleased.Clear();

#if !SILVERLIGHT && !SHARPDX
            KeyboardState state = Keyboard.GetState();
            bool shiftPressed = state.IsKeyDown(Keys.LeftShift) || state.IsKeyDown(Keys.RightShift);
            var keys = state.GetPressedKeys();
#elif SHARPDX
            Keyboard k = new Keyboard(new DirectInput());
            KeyboardState state = k.GetCurrentState();
            k.Dispose();

            bool shiftPressed = state.IsPressed(Keys.LeftShift) || state.IsPressed(Keys.RightShift);
            var keys = state.PressedKeys;
#else
            KeyboardState state = Keyboard.GetState();
            bool shiftPressed = state.IsKeyDown(Keys.Shift);
            var keys = state.GetPressedKeys();
#endif



            // Cycle all the keys down known if any are up currently, remove
            for (int i = 0; i < this.KeysDown.Count; )
            {
#if SHARPDX
                if (!state.PressedKeys.Contains(this.KeysDown[i].XnaKey))
#else
                if (state.IsKeyUp(this.KeysDown[i].XnaKey))
#endif
                {
                    KeysReleased.Add(this.KeysDown[i]);
                    this.KeysDown.Remove(this.KeysDown[i]);
                }
                else
                    i++;
            }

            // For all new keys down, if we don't know them, add them to pressed, add them to down.
#if SHARPDX
            for (int i = 0; i < keys.Count; i++)
#else
            for (int i = 0; i < keys.Length; i++)
#endif
            {
                bool firstPressed = false;

                Input.AsciiKey key = new AsciiKey();
                Input.AsciiKey keyOppositeShift = new AsciiKey();
                Input.AsciiKey activeKey;

                key.Fill(keys[i], shiftPressed);
                keyOppositeShift.Fill(keys[i], !shiftPressed);

                if (this.KeysDown.Contains(key))
                {
                    activeKey = this.KeysDown.First(k => k == key);
                    activeKey.TimeHeld += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    this.KeysDown.Remove(key);
                }
                else if (this.KeysDown.Contains(keyOppositeShift))
                {
                    activeKey = this.KeysDown.First(k => k == keyOppositeShift);
                    activeKey.Character = key.Character;
                    activeKey.TimeHeld += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    this.KeysDown.Remove(keyOppositeShift);
                }
                else
                {
                    activeKey = key;
                    firstPressed = true;
                }

                if (firstPressed)
                {
                    this.KeysPressed.Add(activeKey);
                }
                else if (activeKey.PreviouslyPressed == false && activeKey.TimeHeld >= InitialRepeatDelay)
                {
                    activeKey.PreviouslyPressed = true;
                    activeKey.TimeHeld = 0f;
                    this.KeysPressed.Add(activeKey);
                }
                else if (activeKey.PreviouslyPressed == true && activeKey.TimeHeld >= RepeatDelay)
                {
                    activeKey.TimeHeld = 0f;
                    this.KeysPressed.Add(activeKey);
                }

                this.KeysDown.Add(activeKey);
            }
        }