示例#1
0
 private void Firing(double totalTimeElapsed)
 {
     if (!_HasFirstShotBeenFired)
     {
         ShootNow();
         _HasFirstShotBeenFired = true;
         _TotalTimeElapsed = 0;
     }
     else
     {
         if (_CurrentNbShotsInSalvo > 0)
         {
             if (totalTimeElapsed > TimeBetweenShots)
             {
                 ShootNow();
                 _TotalTimeElapsed = 0;
             }
         }
         else
         {
             _CurrentStatus = WeaponsStatus.RELOADING;
             _TotalTimeElapsed = 0;
         }
     }
 }
示例#2
0
        void IUpdatable.Update(double timeElapsed)
        {
            _TotalTimeElapsed += timeElapsed;

            switch (_CurrentStatus) /// Fat, ugly, shitty, but quick, didn't want to make an actual FSM with actual classes and interfaces and shit :<<
            {
                case WeaponsStatus.IDLE:
                    _CurrentStatus = WeaponsStatus.AIMING;
                    _TotalTimeElapsed = 0;
                    break;

                case WeaponsStatus.AIMING:

                    if (_CurrentNbShotsInSalvo <= 0)
                    {
                        _CurrentStatus = WeaponsStatus.RELOADING;
                        _TotalTimeElapsed = 0;
                        break;
                    }

                    if (_TotalTimeElapsed > _AimingTime)
                    {
                        if (_CurrentNbShotsInSalvo > 0)
                        {
                            _CurrentStatus = WeaponsStatus.FIRING;
                            _TotalTimeElapsed = 0;
                        }
                        else
                        {
                            _CurrentStatus = WeaponsStatus.RELOADING;
                            _TotalTimeElapsed = 0;
                        }
                    }
                    break;

                case WeaponsStatus.RELOADING:
                    if (_TotalTimeElapsed > SalvoReloadTime)
                    {
                        _CurrentNbShotsInSalvo = MaxShotsPerSalvo;
                        _HasFirstShotBeenFired = false;
                        _CurrentStatus = WeaponsStatus.FIRING;
                        _TotalTimeElapsed = 0;
                    }
                    break;

                case WeaponsStatus.FIRING:
                    Firing(_TotalTimeElapsed);
                    break;
            }
        }