Exemplo n.º 1
0
        public override void HandleInput(InputState inputState)
        {
            base.HandleInput(inputState);
            if (inputState.IsKeyNewPressed(Keys.Up))
            {
                _mainMenu.GoUp();
            }
            else if (inputState.IsKeyNewPressed(Keys.Down))
            {
                _mainMenu.GoDown();
            }
            else if (inputState.IsKeyNewPressed(Keys.Enter))
            {
                _mainMenu.PressItem();
            }

            for (int i = 0; i < 4; i++)
            {
                inputState.ActivePlayerIndex = (PlayerIndex)i;
                if (inputState.GetLeftStickPosition().Y == 1)
                {
                    _mainMenu.GoUp();
                }
                else if (inputState.GetLeftStickPosition().Y < -0.5f)
                {
                    _mainMenu.GoDown();
                }
                else if (inputState.IsButtonNewPressed(Buttons.Start))
                {
                    _mainMenu.PressItem();
                }

            }

            if (_mainMenu.PressedItem.text == "Play Local Multiplayer")
            {
                screenManager.AddScreen(new PlayerSelectScreen());
            }
            else if (_mainMenu.PressedItem.text == "Quit Game")
            {
                screenManager.Game.Exit();
            }
        }
Exemplo n.º 2
0
        private void HandleOrientation(InputState inputState)
        {
            switch (_usedControlScheme)
            {
                case ControlScheme.Empty: break;
                case ControlScheme.Keyboard:
                    if (_addedMovement.X != 0 || _addedMovement.Y != 0)
                    {
                        _orientation = _addedMovement;
                        _orientation.Normalize();
                    }
                    break;
                default://Xbox controller
                    if (_useRightStick)
                    {

                        if (!inputState.IsButtonNewPressed(Buttons.RightStick))
                        {
                            _isCannonLocked = true;
                        }
                        Vector2 cannonOrientation = inputState.GetRightStickPosition();
                        if (cannonOrientation.X != 0 || cannonOrientation.Y != 0)
                        {
                            if (_isCannonLocked)
                            {
                                _isCannonLocked = false;
                            }
                            _cannonOrientation = cannonOrientation;
                            _cannonOrientation.Y *= -1;
                            _cannonOrientation.Normalize();
                            cannon.rotation = GeometricHelper.GetAngleFromVectorDirection(_cannonOrientation);
                        }
                        if (_isCannonLocked)
                        {
                            _cannonOrientation = _orientation;
                            cannon.rotation = rotation;
                        }
                    }

                    if (_addedMovement.X != 0 || _addedMovement.Y != 0)
                    {
                        _orientation = inputState.GetLeftStickPosition();
                        _orientation.Y *= -1;
                        _orientation.Normalize();
                        rotation = GeometricHelper.GetAngleFromVectorDirection(_orientation);
                    }

                    break;
            }

            InputState.StickPosition currentPosition = InputState.ConvertVectorDirectionToStickPosition(_orientation);
            string newAnimation = "";
            if (animationMap.ContainsKey(currentPosition))
            {
                newAnimation = animationMap[currentPosition];
            }

            if (!newAnimation.Equals(_currentAnimationState))
            {
                _currentAnimationState = newAnimation;
                SetCurrentAnimationState(_currentAnimationState);
            }
            if (_addedMovement.X == 0 && _addedMovement.Y == 0)
            {
                PauseAnimation();
            }
            else
            {
                ResumeAnimation();
            }
        }
Exemplo n.º 3
0
        private void HandleMovement(InputState inputState, GameTime gameTime)
        {
            _addedMovement = new Vector2(0, 0);
            if (IsXboxControllerScheme(_usedControlScheme))
            {
                _addedMovement = inputState.GetLeftStickPosition();
                //Dualstick
                _addedMovement.Y *= -1;
            }
            else if (_usedControlScheme == ControlScheme.Keyboard)
            {
                if (inputState.IsKeyPressed(Keys.Left)) { _addedMovement.X = -1.0f; }
                else if (inputState.IsKeyPressed(Keys.Right)) { _addedMovement.X = 1.0f; }
                if (inputState.IsKeyPressed(Keys.Up)) { _addedMovement.Y = -1.0f; }
                else if (inputState.IsKeyPressed(Keys.Down)) { _addedMovement.Y = 1.0f; }

                if (_addedMovement.X != 0 || _addedMovement.Y != 0)
                {
                    rotation = GeometricHelper.GetAngleFromVectorDirection(_addedMovement);
                }
            }
            oldVelocity = velocity;
            if (_addedMovement != Vector2.Zero)
            {
                velocity = Math.Min(oldVelocity + (acceleration), _movementSpeed / _chargeLevel);
            }
            else
            {
                velocity = Math.Max(oldVelocity - acceleration, 0);
            }
            position += _addedMovement * ((oldVelocity + velocity) / 2);
        }