Пример #1
0
        /// <summary>
        /// Reads the latest state of the keyboard and gamepad.
        /// </summary>
        public void Update()
        {
            // Read all input state of the keyboard and support game pad controllers
            for (int i = 0; i < MaxInputs; i++)
            {
                this.LastKeyboardStates[i] = this.CurrentKeyboardStates[i];
                this.LastGamePadStates[i]  = this.CurrentGamePadStates[i];

                this.CurrentKeyboardStates[i] = Keyboard.GetState((PlayerIndex)i);
                this.CurrentGamePadStates[i]  = GamePad.GetState((PlayerIndex)i);

                // Keep track of whether a gamepad has ever been
                // connected, so we can detect if it is unplugged.
                if (this.CurrentGamePadStates[i].IsConnected)
                {
                    this.GamePadWasConnected[i] = true;
                }
            }

            // Add the capability to read data from the Nintendo Controller
            this.LastNintendoControllerState    = this.CurrentNintendoControllerState;
            this.CurrentNintendoControllerState = this._nintendoController.GetState();
            if (this.CurrentNintendoControllerState.IsConnected)
            {
                this.NintendoControllerWasConnected = true;
            }
        }
Пример #2
0
 public void Update(GameTime gameTime, NintendoControllerState controllerState, KeyboardState keyboardState)
 {
     GetInput(controllerState, keyboardState);
     ApplyPhysics(gameTime);
     //ClearInputs();
     movement = 0.0f;
 }
Пример #3
0
        public void Update(GameTime gameTime, NintendoControllerState controllerState, KeyboardState keyboardState)
        {
            _player.Update(gameTime, controllerState, keyboardState);

            foreach (SodaCan can in _cans)
            {
                can.Update(gameTime);
            }

            HandleFallingCans();

            HandleCollisions();
        }
Пример #4
0
        private void GetInput(NintendoControllerState controllerState, KeyboardState keyboardState)
        {
            //movement = controllerState.DPad.Left * MoveStickScale;
            movement = 0;// MoveStickScale;

            if (controllerState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left))
            {
                movement = -1.0f;
            }
            else if (controllerState.IsButtonDown(Buttons.DPadRight) ||
                     keyboardState.IsKeyDown(Keys.Right))
            {
                movement = 1.0f;
            }

            if (controllerState.IsButtonDown(Buttons.A) ||
                keyboardState.IsKeyDown(Keys.Space))
            {
                if (!HasCan)
                {
                    _isCatching = true;
                }
                else
                {
                    _isCatching = false;
                }
            }
            else
            {
                _isCatching = false;

                if (HasCan)
                {
                    ReleaseCan();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Updates the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(GameTime gameTime)
        {
            // duh?
            if (_endReached)
            {
                return;
            }

            _controllerState = _nintendoController.GetState();
            _keyboardState   = Keyboard.GetState();

            ClearInputs();
            Direction?destinationDirection = GetInput();
            Cell      destinationCell      = null;

            if (destinationDirection.HasValue)
            {
                if (_currentCell.IsEnd && destinationDirection.Value == Direction.Up)
                {
                    _endReached = true;
                    return;
                }

                destinationCell = _maze.GetDestinationCell(_currentCell, destinationDirection.Value);
            }

            if (destinationCell != null)
            {
                _currentCell = destinationCell;
            }

            if (_currentCell.HasDollar)
            {
                this._dollarSound.Play();
                this._currentCell.RemoveDollar();
                this._points += _dollarValue;
            }
        }
Пример #6
0
 private void HandleInput()
 {
     _controllerState = _nintendoController.GetState();
     _keyboardState   = Keyboard.GetState();
 }