Exemple #1
0
            public void Update(GameTime gameTime)
            {
                ReviewDirectionFaced();

                decimal differenceInRotation = GetChangeOfRotationRequired(this.CurrentRotation, this._desiredRotation);

                if (differenceInRotation == 0)
                {
                    return;
                }
                RotationalMotion directionOfTravel          = (RotationalMotion)Math.Sign(differenceInRotation);
                decimal          speedOfRotation            = (int)directionOfTravel * 0.25m * Constants.BaseDistancesMovedPerSecond;
                double           timeNeededToFinishRotation = (double)(differenceInRotation / speedOfRotation);
                var  remainingTime        = gameTime.ElapsedGameTime.TotalSeconds;
                bool hasCompletedRotation = timeNeededToFinishRotation <= remainingTime;

                if (hasCompletedRotation)
                {
                    this._currentRotationRelativeToHull = this._desiredRotation - this._tank._hullRotation;
                }
                else
                {
                    decimal changeInRotation = (decimal)((double)speedOfRotation * remainingTime);
                    this._currentRotationRelativeToHull += changeInRotation;
                }
                NormaliseRotation(ref this._currentRotationRelativeToHull);
            }
Exemple #2
0
        private bool TryToCompleteRotationToTarget(ref double remainingTime, decimal targetRotation, RotationalMotion directionOfTravel)
        {
            decimal speedOfRotation            = (int)directionOfTravel * 0.5m * Constants.BaseDistancesMovedPerSecond * this.SpeedAdjustmentFactor;
            decimal changeOfRotation           = GetChangeOfRotationRequired(this._hullRotation, targetRotation);
            double  timeNeededToFinishRotation = (double)(changeOfRotation / speedOfRotation);
            bool    hasCompletedRotation       = timeNeededToFinishRotation <= remainingTime;

            if (hasCompletedRotation)
            {
                remainingTime     -= timeNeededToFinishRotation;
                this._hullRotation = targetRotation;
            }
            else
            {
                decimal changeInRotation = (decimal)((double)speedOfRotation * remainingTime);
                this._hullRotation += changeInRotation;
                remainingTime       = 0;
            }
            NormaliseRotation(ref this._hullRotation);

            return(hasCompletedRotation);
        }