Example #1
0
 public override void HandleInput(InputState inputState)
 {
     base.HandleInput(inputState);
     HandleGameEntering(inputState);
     HandleGameExiting(inputState);
     HandleGameStarting(inputState);
     HandleColorSelection(inputState);
 }
        public override void HandleInput(InputState inputState)
        {
            if (_currentSymbol == Symbol.Wait && timer < waitTime)
            {
                timer += screenManager.currentGameTime.ElapsedGameTime.Milliseconds;

            }
            else if (_currentSymbol == Symbol.Wait && timer >= waitTime)
            {
                timer = 0;
                waitTime = 0;
                _currentSymbol = Symbol.None;
            }
            else if (_currentSymbol == Symbol.Switch)
            {
                if (inputState.IsKeyNewPressed(Keys.X))
                {
                    _currentSymbol = Symbol.None;
                }
            }
            if (_currentSymbol == Symbol.Click && inputState.IsKeyNewPressed(Keys.X))
            {
                _currentSymbol = Symbol.None;
                _clickDots = "";
                if (_currentString.Length == 0)
                {
                    if (_messages.Count() > 1)
                    {
                        Console.WriteLine(_messages.Count());
                        _messages.Remove(_messages[0]);
                        _currentString = _messages[0];
                        _drawString = "";
                    }
                    else
                    {
                        //Event handling was made here before - Removed because it did not work as intented
                    }
                }
            }
            else if (_currentSymbol == Symbol.Char)
            {
                _currentSymbol = Symbol.None;
            }
            if (!_parsing && timer>= waitTime && _currentSymbol == Symbol.None)
            {
                if (_currentString.Length > 0)
                {
                    ParseNextSymbol();
                }
                else
                {
                    _currentSymbol = Symbol.Click;
                }
            }
        }
Example #3
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();
            }
        }
Example #4
0
 public virtual void HandleInput(InputState inputState)
 {
 }
Example #5
0
        public void HandleInput(InputState inputState)
        {
            if (!showingDescription)
            {
                if (currentlySelected && childSelected == null && children.Count >= 0)
                {

                    if (inputState.IsKeyNewPressed(Keys.Up) && index > 0)
                    {
                        children[index].currentlyMarked = false;
                        index--;
                        children[index].currentlyMarked = true;
                        childMarked = children[index];
                        if (scrollable && !firstIndexSeen && index == 1)
                        {
                            scrollIndex--;
                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.Down) && index + 1 < children.Count)
                    {
                        children[index].currentlyMarked = false;
                        index++;
                        children[index].currentlyMarked = true;
                        childMarked = children[index];
                        if (scrollable && !lastIndexSeen && lastDrawnIndex == index)
                        {
                            scrollIndex++;
                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.Z))
                    {
                        if (level > 0)
                        {
                            currentlySelected = false;
                            currentlyMarked = true;
                            if (children.Count() > 0)
                            {
                                childMarked.currentlyMarked = false;
                                childSelected = null;
                            }
                            if (parent != null)
                            {
                                parent.childSelected = null;
                                parent.childMarked = parent.children[parent.index];
                            }

                        }
                    }
                    else if (inputState.IsKeyNewPressed(Keys.X) && children.Count() > 0 && !children[index].locked)
                    {
                        currentlySelected = true;
                        currentlyMarked = false;
                        children[index].currentlySelected = true;
                        childSelected = children[index];
                        if (parent != null)
                        {
                            parent.childMarked = null;
                        }
                        childMarked.currentlyMarked = false;
                        childMarked = null;
                        currentLevel++;
                    }
                    else if (inputState.IsKeyNewPressed(Keys.H) && childMarked != null)
                    {
                        showingDescription = true;
                    }
                }
                else if (childSelected != null)
                {
                    childSelected.HandleInput(inputState);
                }
            }
            else
            {
                showingDescription = false;
            }
        }
Example #6
0
        public override void HandleInput(InputState inputState)
        {
            base.HandleInput(inputState);

            bool reset = false;
            for (int i = 0; i < numberOfPlayers; i++)
            {
                _players[i].HandleInput(inputState, screenManager.currentGameTime);
                if (_playersRemaining.Count < 2)
                {
                    switch (usedControls[i])
                    {
                        case Tank.ControlScheme.Keyboard:
                            reset = inputState.IsKeyNewPressed(Keys.S);
                            break;
                        default:
                            inputState.ActivePlayerIndex = _players[i].GamePadIndex;
                            reset = inputState.IsButtonNewPressed(Buttons.Start);
                            break;
                    }
                    if (reset) StartNextRound(); break;
                }
            }
        }
Example #7
0
        private void HandleShooting(InputState inputState, GameTime gameTime)
        {
            _coolDownTimer -= gameTime.ElapsedGameTime.Milliseconds;
            if (_hasFastAttack && _coolDownTimer <= 0)
            {
                Shoot();
                return;
            }
            bool isShooting = false;
            bool isCharging = false;
            switch (_usedControlScheme)
            {
                case ControlScheme.Empty: break;
                case ControlScheme.Keyboard:
                    isShooting = inputState.IsKeyNewReleased(Keys.Space);
                    isCharging = inputState.IsKeyPressed(Keys.Space);
                    break;
                default://Xbox controller
                    if (!_useRightStick)
                    {
                        isShooting = inputState.IsButtonNewReleased(Buttons.X);
                        isCharging = inputState.IsButtonPressed(Buttons.X);
                    }
                    else
                    {
                        isShooting = inputState.IsButtonNewReleased(Buttons.RightTrigger);
                        isCharging = inputState.IsButtonPressed(Buttons.RightTrigger);
                    }

                    break;
            }

            if (isCharging && _timeCharged < cFullyChargeTime)
            {
                _timeCharged = Math.Min(_timeCharged + gameTime.ElapsedGameTime.Milliseconds, cFullyChargeTime);
                if (_timeCharged >= cFullyChargeTime || (_timeCharged >= cFullyChargeTime / 2 && _hasBigAmmo))
                {
                    _scale = 1.4f;
                    cannon.SetScale(1.4f);
                    _chargeLevel = 3;
                }
                else if (_timeCharged >= cFullyChargeTime / 2)
                {
                    _scale = 1.2f;
                    cannon.SetScale(1.2f);
                    _chargeLevel = 2;
                }
            }
            else
            {

                if (isShooting && _coolDownTimer <= 0)
                {
                    Shoot();
                }
            }
        }
Example #8
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();
            }
        }
Example #9
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);
        }
Example #10
0
        public void HandleInput(InputState inputState, GameTime gameTime)
        {
            if (canAct)
            {
                if (_health > 0)
                {
                    if (IsXboxControllerScheme(_usedControlScheme))
                    {
                        inputState.ActivePlayerIndex = _gamePadIndex;
                    }
                    HandleMovement(inputState, gameTime);
                    HandleOrientation(inputState);
                    HandleShooting(inputState, gameTime);

                    //Powerup
                    if (powerUpInSlot != null &&
                        (inputState.IsButtonNewPressed(Buttons.Y) ||
                        inputState.IsKeyNewPressed(Keys.LeftShift)))
                    {
                        ActivatePowerup();
                    }
                }

            }
        }
Example #11
0
 private void HandleGameStarting(InputState inputState)
 {
     if (_playersPlaying > 1)
     {
         bool gamepadPressedStart = false;
         for (int i = 0; i < 4; i++)
         {
             inputState.ActivePlayerIndex = (PlayerIndex)i;
             if (_gamePadSlotsUsed[i] && inputState.IsButtonNewPressed(Buttons.Start))
             {
                 gamepadPressedStart = true;
                 break;
             }
         }
         if (gamepadPressedStart || inputState.IsKeyNewPressed(Keys.S))
         {
             screenManager.AddScreen(new PlayScreen(_playersPlaying, _selectedControls, _selectedTeams));
         }
     }
 }
Example #12
0
        private void HandleGameExiting(InputState inputState)
        {
            if (_playersPlaying > 0)
            {
                for (int i = 0; i < _playersPlaying; i++)
                {
                    if (_selectedControls[i] == Tank.ControlScheme.Keyboard)
                    {
                        if (inputState.IsKeyNewPressed(Keys.Q))
                        {
                            _selectedControls[i] = Tank.ControlScheme.Empty;
                            _selectedTeams[i] = -1;
                            _tankSprites[i].Hide();
                            _keyboardSlotsLeft++;
                            _playersPlaying--;

                        }
                    }
                    else if (_selectedControls[i] != Tank.ControlScheme.Empty)
                    {
                        inputState.ActivePlayerIndex = (PlayerIndex)(int)(_selectedControls[i] - 3);
                        if (inputState.IsButtonNewPressed(Buttons.B))
                        {
                            _gamePadSlotsUsed[(int)inputState.ActivePlayerIndex] = false;
                            _selectedControls[i] = Tank.ControlScheme.Empty;
                            _tankSprites[i].Hide();
                            _selectedTeams[i] = -1;
                            _playersPlaying--;
                        }
                    }
                }
            }
        }
Example #13
0
        private void HandleGameEntering(InputState inputState)
        {
            if (_playersPlaying < 4)
            {
                if (inputState.IsKeyNewPressed(Keys.Enter) && _keyboardSlotsLeft > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (_selectedControls[i] == Tank.ControlScheme.Empty)
                        {
                            _keyboardSlotsLeft--;
                            _selectedControls[i] = Tank.ControlScheme.Keyboard;
                            ChangeTeam(1, i);
                            _tankSprites[_selectedTeams[i]].Show();
                            _playersPlaying++;
                            break;
                        }
                    }

                }
                for (int i = 0; i < 4; i++)
                {
                    inputState.ActivePlayerIndex = (PlayerIndex)i;
                    if (!_gamePadSlotsUsed[i] && inputState.IsButtonNewPressed(Buttons.A))
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            if (_selectedControls[j] == Tank.ControlScheme.Empty)
                            {
                                _gamePadSlotsUsed[i] = true;
                                _selectedControls[j] = (Tank.ControlScheme)(i + 3);
                                ChangeTeam(1, j);
                                _tankSprites[_selectedTeams[j]].Show();
                                _playersPlaying++;
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #14
0
        private void HandleColorSelection(InputState inputState)
        {
            if (_playersPlaying > 0)
            {
                for (int i = 0; i < _playersPlaying; i++)
                {
                    switch (_selectedControls[i])
                    {
                        case Tank.ControlScheme.Empty: break;
                        case Tank.ControlScheme.Keyboard:
                            if (inputState.IsKeyNewPressed(Keys.Left))
                            {
                                _tankSprites[_selectedTeams[i]].Hide();
                                float rotation = _tankSprites[_selectedTeams[i]].rotation;
                                ChangeTeam(-1, i);
                                _tankSprites[_selectedTeams[i]].Show();
                                _tankSprites[_selectedTeams[i]].rotation = rotation;

                            }
                            else if (inputState.IsKeyNewPressed(Keys.Right))
                            {
                                _tankSprites[_selectedTeams[i]].Hide();
                                float rotation = _tankSprites[_selectedTeams[i]].rotation;
                                ChangeTeam(1, i);
                                _tankSprites[_selectedTeams[i]].Show();
                                _tankSprites[_selectedTeams[i]].rotation = rotation;
                            }
                            break;
                        default:
                            inputState.ActivePlayerIndex = (PlayerIndex)(int)(_selectedControls[i] - 3);
                            if (inputState.IsButtonNewPressed(Buttons.LeftThumbstickLeft))
                            {
                                _tankSprites[_selectedTeams[i]].Hide();
                                ChangeTeam(-1, i);
                                _tankSprites[_selectedTeams[i]].Show();
                            }
                            else if (inputState.IsButtonNewPressed(Buttons.LeftThumbstickRight))
                            {
                                _tankSprites[_selectedTeams[i]].Hide();
                                ChangeTeam(1, i);
                                _tankSprites[_selectedTeams[i]].Show();
                            }
                            break;

                    }
                }
            }
        }