Esempio n. 1
0
        private void ShootChargedBullet()
        {
            if (_chargedShotBullet == null)
            {
                return;
            }

            _playerChargedShotShootingPosition.RemoveChild(_chargedShotBullet);
            _playerBulletHolder.AddChild(_chargedShotBullet);

            float maxDamage    = _chargedShotBullet.GetBulletDamage() + _currentDamageDiff;
            float mappedDamage = ExtensionFunctions.Map(_chargeWeaponCurrentScale,
                                                        0, chargeGunMaxScaleAmount, 0, maxDamage);

            _chargedShotBullet.SetBulletDamage(mappedDamage);
            _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition());
            _chargedShotBullet.SetGlobalScale(Vector2.One * _chargeWeaponCurrentScale);

            float currentRotation = _playerRoot.GetRotation();

            _chargedShotBullet.SetGlobalRotation(currentRotation);

            _chargedShotBullet.SetAsDynamicBullet();
            _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Rigid);

            float xVelocity = Mathf.Cos(currentRotation);
            float yVelocity = Mathf.Sin(currentRotation);

            _chargedShotBullet.LaunchBullet(new Vector2(xVelocity, yVelocity).Normalized());

            _chargedShotBullet = null;

            bulletShot?.Invoke(_currentWeaponType);
        }
Esempio n. 2
0
        private void HandleWeaponShooting()
        {
            switch (_currentWeaponType)
            {
            case WeaponType.SingleShot:
                float currentRotation = _playerRoot.GetRotation();
                float xVelocity       = Mathf.Cos(currentRotation);
                float yVelocity       = Mathf.Sin(currentRotation);
                ShootSingleShotBullet(new Vector2(xVelocity, yVelocity));
                break;

            case WeaponType.Shotgun:
                ShootShotGunBullet();
                break;

            case WeaponType.ChargeGun:
            {
                _chargeWeaponCurrentScale = 1;

                _chargedShotBullet = (ChargedBullet)playerChargedBulletPrefab.Instance();
                _playerChargedShotShootingPosition.AddChild(_chargedShotBullet);

                _chargedShotBullet.SetGlobalPosition(_playerChargedShotShootingPosition.GetGlobalPosition());
                _chargedShotBullet.SetAsStaticBullet();
                _chargedShotBullet.SetMode(RigidBody2D.ModeEnum.Kinematic);
            }

            break;

            default:
                throw new ArgumentOutOfRangeException(nameof(_currentWeaponType), _currentWeaponType, null);
            }
        }