Exemplo n.º 1
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();
                }
            }
        }