Example #1
0
        private int GetAlphaForCoordinates(int objX, int objY, ICharacter character)
        {
            if (!_configurationProvider.ShowTransition)
            {
                return(255);
            }

            //get the farther away of X or Y coordinate for the map object
            var metric = Math.Max(Math.Abs(objX - character.RenderProperties.MapX),
                                  Math.Abs(objY - character.RenderProperties.MapY));

            int alpha;

            if (!_mapTransitionState.StartTime.HasValue ||
                metric < _mapTransitionState.TransitionMetric ||
                _mapTransitionState.TransitionMetric == 0)
            {
                alpha = 255;
            }
            else if (metric == _mapTransitionState.TransitionMetric)
            {
                var ms = (DateTime.Now - _mapTransitionState.StartTime).TotalMilliseconds;
                alpha = (int)Math.Round(ms / TRANSITION_TIME_MS * 255);

                if (ms / TRANSITION_TIME_MS >= 1)
                {
                    _mapTransitionState = new MapTransitionState(DateTime.Now, _mapTransitionState.TransitionMetric + 1);
                }
            }
            else
            {
                alpha = 0;
            }

            return(alpha);
        }
Example #2
0
 public void StartMapTransition()
 {
     _mapTransitionState = new MapTransitionState(DateTime.Now, 1);
 }