Exemplo n.º 1
0
    private void Awake()
    {
        _magnetic      = GetComponent <Magnetic>();
        _currentState  = RoyStates.None;
        _currentEnergy = _maxEnergy;
        OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
        _currentFuel = _maxFuel;
        OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        _energyPerSecond   = (float)_maxEnergy / _energyTimeDuration;
        _rechargePerSecond = (float)_maxFuel / _totalTimeToReloadFullFuel;

        _aimController = GetComponentInChildren <AimController>();
        var playerInputComponent = GetComponent <PlayerInput>();

        _magnetic.OnPull += _onPlayerPull_Magnetic;

        _actionMove            = playerInputComponent.actions["Move"];
        _actionJump            = playerInputComponent.actions["Jump"];
        _actionJump.performed += _actionJump_performed;
        _actionJump.canceled  += _actionJump_canceled;
        _actionMov1            = playerInputComponent.actions["Mov1"];
        _actionMov1.started   += _actionMov1_started;
        _actionMov1.canceled  += _actionMov1_canceled;
        _actionMov2            = playerInputComponent.actions["Mov2"];
        _actionMov2.performed += _actionMov2_performed;
        _actionMov2.canceled  += _actionMov2_canceled;
        _animator.Play("Roy_Armature_Idle");
    }
Exemplo n.º 2
0
    private void Awake()
    {
        _magnetic         = GetComponent <Magnetic>();
        _magnetic.OnPull += _onPlayerPull_Magnetic;
        _currentState     = KlunkState.None;
        _currentFuel      = _maxFuel;
        OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        _currentEnergy = _maxEnergy;
        OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
        _fuelPerSecond     = (float)_maxFuel / _fuelTimeDuration;
        _rechargePerSecond = (float)_maxEnergy / _totalTimeToReloadFullEnergy;

        _frontAttack = GetComponentInChildren <FrontAttack>();
        _frontAttack.gameObject.SetActive(false);
        _frontAttack.OnTriggerEnterEvent += _frontAttackChecker_OnTriggerEnterEvent;
        _characterController              = GetComponent <KlunkCharController>();
        _frictionController = GetComponent <FrictionController>();

        var playerInput = GetComponent <PlayerInput>();

        _actionMove            = playerInput.actions["Move"];
        _actionJump            = playerInput.actions["Jump"];
        _actionJump.performed += _actionJump_performed;
        _actionJump.canceled  += _actionJump_canceled;
        _actionMov1            = playerInput.actions["Mov1"];
        _actionMov2            = playerInput.actions["Mov2"];
        _actionMov2.performed += _actionMov2_performed;
        _actionMov2.canceled  += _actionMov2_canceled;
        inGameUIController     = FindObjectOfType <InGameUIController>();
    }
Exemplo n.º 3
0
    private void FixedUpdate()
    {
#if UNITY_EDITOR
        if (_infinityMode)
        {
            _currentEnergy = _maxEnergy;
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
            _currentFuel = _maxFuel;
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }
#endif
        if (_currentEnergy <= 0)
        {
            return;
        }

        if (_currentEnergy > 0)
        {
            _energyConsumed += _energyPerSecond * Time.fixedDeltaTime;
        }
        if (_energyConsumed >= 1)
        {
            _energyConsumed -= 1;
            _currentEnergy   = Mathf.Clamp(--_currentEnergy, 0, _maxEnergy);
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
        }

        if (_currentFuel < _maxFuel)
        {
            _fuelRecharged += _rechargePerSecond * Time.fixedDeltaTime;
        }
        if (_fuelRecharged >= 1)
        {
            _fuelRecharged -= 1;
            _currentFuel    = Mathf.Clamp(++_currentFuel, 0, _maxFuel);
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }

        switch (_currentState)
        {
        case RoyStates.Hooked:
            if (_currentFuel <= 0 || !_actionMovHookPressed)
            {
                _currentState = RoyStates.None;
                UnHook();
                _characterController.SetHook(false);
                return;
            }
            _fuelConsumed += _hookFuelCostPerSecond * Time.fixedDeltaTime;
            if (_fuelConsumed >= 1)
            {
                _fuelConsumed -= 1;
                _currentFuel   = Mathf.Clamp(--_currentFuel, 0, _maxFuel);
                OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
            }
            _characterController.Move(_actionMove.ReadValue <Vector2>(), 1, false);
            break;

        case RoyStates.Boosting:
            if (!_isHovering)
            {
                _isHovering = true;
                //AudioManager.instance.Play("roy_hover");
            }
            if (_currentFuel <= 0 || !_actionMovBoostPressed)
            {
                _currentState = RoyStates.None;
                //AudioManager.instance.Stop("roy_hover");
                _isHovering = false;
            }
            _fuelConsumed += _boostCostPerSecond * Time.fixedDeltaTime;
            if (_fuelConsumed >= 1)
            {
                _fuelConsumed -= 1;
                _currentFuel   = Mathf.Clamp(--_currentFuel, 0, _maxFuel);
                OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
            }
            break;

        default:
            if (!_isWalking)
            {
                _isWalking = true;

                //AudioManager.instance.Play("roy_walk");
            }
            _characterController.Move(_actionMove.ReadValue <Vector2>(), 1f, _jump);
            if (_actionMovHookPressed &&
                _currentFuel >= _hookFuelCostPerSecond &&
                HasHookPoint())
            {
                _characterController.SetHook(true);
                _currentState = RoyStates.Hooked;
                //AudioManager.instance.Stop("roy_walk");
                _isWalking = false;
                HookTo(_aimHitInfo.point);
                return;
            }
            if (_actionMovBoostPressed && _currentFuel >= _boostCostPerSecond)
            {
                _currentState = RoyStates.Boosting;
                //AudioManager.instance.Stop("roy_walk");
                _isWalking = false;
                return;
            }
            break;
        }
    }
Exemplo n.º 4
0
 public void AddFuel()
 {
     _currentFuel = Mathf.Clamp(_currentFuel + _collectedBottleRechargeValue, 0, _maxFuel);
     OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
     //AudioManager.instance.Play("klunk_fuelrecharge");
 }
Exemplo n.º 5
0
    private void FixedUpdate()
    {
#if UNITY_EDITOR
        if (_infinityMode)
        {
            _currentEnergy = _maxEnergy;
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
            _currentFuel = _maxFuel;
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }
#endif
        if (_currentFuel <= 0)
        {
            return;
        }

        if (_currentFuel > 0)
        {
            _fuelConsumed += _fuelPerSecond * Time.fixedDeltaTime;
        }
        if (_fuelConsumed >= 1)
        {
            _fuelConsumed -= 1;
            _currentFuel   = Mathf.Clamp(--_currentFuel, 0, _maxFuel);
            OnCurrentFuelChange?.Invoke((float)_currentFuel / _maxFuel);
        }

        if (_currentEnergy < _maxEnergy)
        {
            _energyRecharged += _rechargePerSecond * Time.fixedDeltaTime;
        }
        if (_energyRecharged >= 1)
        {
            _energyRecharged -= 1;
            _currentEnergy    = Mathf.Clamp(++_currentEnergy, 0, _maxEnergy);
            OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
        }

        switch (_currentState)
        {
        case KlunkState.Dashing:
            _remainingTimeDash -= Time.fixedDeltaTime;
            if (!_isDashing)
            {
                _isDashing = true;
                //AudioManager.instance.Play("klunk_dash");
            }
            if (_remainingTimeDash <= 0 || _hitWallWhileDash)
            {
                _currentState = KlunkState.None;
                _characterController.IgnoreAirSpeed(false);
                _characterController.Move(Vector2.zero, 0, _jump);
                _characterController.RemoveFreezeConstraint(RigidbodyConstraints.FreezePositionY);
                _frontAttack.gameObject.SetActive(false);
                _hitWallWhileDash = false;
                _frictionController.SetMaxFriction();
                _characterController.IgnoreHorizontalClampedSpeed(false);
                _characterController.IgnoreSpeedSmooth(false);
                _characterController.DontIncrementSpeed(false);
                _isDashing = false;
                OnEndDash?.Invoke(transform.position);
            }
            break;

        case KlunkState.Sk8erBoi:
            if (_currentEnergy <= 0 || !_actionMov2Pressed)
            {
                _currentState = KlunkState.None;
                _characterController.SetBaseSpeedMultiplier(1);
                OnEndSkate?.Invoke(transform.position);
                _isSkating = false;
                //AudioManager.instance.Stop("klunk_skate");
                return;
            }
            if (!_isSkating)
            {
                _isSkating = true;
                //AudioManager.instance.Play("klunk_skate");
            }
            _characterController.Move(_actionMove.ReadValue <Vector2>(), _sk8SpeedFactor, _jump);
            _energyConsumed += _sk8erBoiEnergyCostPerSecond * Time.fixedDeltaTime;
            if (_energyConsumed >= 1)
            {
                _energyConsumed -= 1;
                _currentEnergy   = Mathf.Clamp(--_currentEnergy, 0, _maxEnergy);
                OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
            }
            break;

        default:
            _characterController.Move(_actionMove.ReadValue <Vector2>(), 1, _jump);
            if (!_isWalking)
            {
                _isWalking = true;
                //AudioManager.instance.Play("klunk_walk");
            }
            if (_actionMov1.triggered && _currentEnergy >= _dashEnergyCost)
            {
                _characterController.IgnoreAirSpeed(true);
                if (_characterController.FacedRight)
                {
                    _characterController.Move(Vector2.right, _dashSpeedFactor, _jump);
                }
                else
                {
                    _characterController.Move(-Vector2.right, _dashSpeedFactor, _jump);
                }
                _characterController.AddFreezeConstraint(RigidbodyConstraints.FreezePositionY);
                _frontAttack.gameObject.SetActive(true);
                _remainingTimeDash  = _dashMaxDistance / (_characterController.BaseSpeed * _dashSpeedFactor);
                _remainingTimeDash -= Time.fixedDeltaTime;
                _currentState       = KlunkState.Dashing;
                _currentEnergy      = Mathf.Clamp(_currentEnergy - _dashEnergyCost, 0, _maxEnergy);
                OnCurrentEnergyChange?.Invoke((float)_currentEnergy / _maxEnergy);
                _frictionController.SetZeroFriction();
                _characterController.IgnoreHorizontalClampedSpeed(true);
                _characterController.IgnoreSpeedSmooth(true);
                _characterController.DontIncrementSpeed(true);
                OnStartDash?.Invoke(transform.position);
                temp_startPosition = transform.position;
                _isWalking         = false;
                //AudioManager.instance.Play("klunk_walk");
                return;
            }
            else if (_actionMov2Pressed && _currentEnergy > _sk8erBoiEnergyCostPerSecond)
            {
                _currentState = KlunkState.Sk8erBoi;
                _characterController.SetBaseSpeedMultiplier(_sk8SpeedFactor);
                OnStartSkate?.Invoke(transform.position);
                _isWalking = false;
                //AudioManager.instance.Play("klunk_walk");
                return;
            }
            break;
        }
    }