Beispiel #1
0
        private void AnimateMazeRunnerVisualToCell(int col, int row, TravelSpeed travelSpeed, int crumbCount)
        {
            _animationIsRunning = true;

            if (_batch != null)
            {
                _batch.Dispose();
            }
            _batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation);

            var animation = _compositor.CreateVector3KeyFrameAnimation();
            var easing    = _compositor.CreateLinearEasingFunction();

            var destination = new Vector3((float)(col * _cellSize), (float)(row * _cellSize), 0.0F);

            animation.InsertKeyFrame(1.0f, destination, easing);

            switch (travelSpeed)
            {
            case TravelSpeed.Walk:
                animation.Duration = TimeSpan.FromMilliseconds(500 * crumbCount);
                break;

            case TravelSpeed.Run:
                animation.Duration = TimeSpan.FromSeconds(0.1);
                break;

            case TravelSpeed.Jump:
                animation.Duration = TimeSpan.FromMilliseconds(1);
                break;
            }
            _mazeRunnerVisual.StartAnimation(nameof(_mazeRunnerVisual.Offset), animation);
            _batch.End();
            _batch.Completed += _batch_Completed;
        }
 public static int TravelSpeedToInt(TravelSpeed speed, object parameter)
 {
     int max = 2;
     if (parameter is double || parameter is int)
         max = (int)parameter;
     int mid = (int)Math.Round(max / 2d);
     return speed == TravelSpeed.Slow ? 0 : speed == TravelSpeed.Normal ? mid : max;
 }
Beispiel #3
0
        private int getDurationInMins(TravelSpeed SpeedType, string fastPacedDefaultTime, string slowPacedDefaultTime, int popularPacedDefaultTime)

        {
            int minsToReturm;

            if (SpeedType == TravelSpeed.Fast)
            {
                minsToReturm = int.Parse(fastPacedDefaultTime) * 60;
            }
            else if (SpeedType == TravelSpeed.Slow)
            {
                minsToReturm = int.Parse(slowPacedDefaultTime) * 60;
            }
            else
            {
                minsToReturm = popularPacedDefaultTime * 60;
            }

            return(minsToReturm);
        }
Beispiel #4
0
        private void DropBreadCrumb(int col, int row, TravelSpeed travelSpeed, int crumbCount)
        {
            var visual = _compositor.CreateSpriteVisual();

            visual.Size    = new Vector2(_cellSize, _cellSize);
            visual.Brush   = _breadCrumbBrush;
            visual.Opacity = 0;

            var cell = MazeGrid.Children.Cast <FrameworkElement>().First(b => Grid.GetRow(b) == _curRow && Grid.GetColumn(b) == _curCol) as Border;

            ElementCompositionPreview.SetElementChildVisual(cell, visual);

            var animation = _compositor.CreateScalarKeyFrameAnimation();
            var easing    = _compositor.CreateLinearEasingFunction();

            animation.InsertKeyFrame(1.0f, 1, easing);

            switch (travelSpeed)
            {
            case TravelSpeed.Walk:
                animation.Duration  = TimeSpan.FromMilliseconds(500);
                animation.DelayTime = TimeSpan.FromMilliseconds(500 * crumbCount);
                break;

            case TravelSpeed.Run:
                animation.Duration  = TimeSpan.FromSeconds(0.1 * crumbCount);
                animation.DelayTime = TimeSpan.FromMilliseconds(0.1 * crumbCount);
                break;

            case TravelSpeed.Jump:
                animation.Duration  = TimeSpan.FromMilliseconds(1 * crumbCount);
                animation.DelayTime = TimeSpan.FromMilliseconds(1 * crumbCount);
                break;
            }
            visual.StartAnimation(nameof(visual.Opacity), animation);
        }
 public static string TravelSpeedToString(TravelSpeed speed)
 {
     return speed.ToString().ToLower();
 }
 public static string GetTravelSpeedString(TravelType type, TravelSpeed speed, bool imperial = false)
 {
     var travelSpeed = GetTravelSpeed(type, speed, imperial);
     int idxImp = imperial ? 0 : 1;
     string[] label = { " mph", " km/h" };
     string result = travelSpeed.ToString() + label[idxImp];
     return result;
 }
        public static double GetTravelSpeed(TravelType type, TravelSpeed speed, bool imperial = false)
        {
            int idxSpeed = speed == TravelSpeed.Slow ? 0 : speed == TravelSpeed.Normal ? 1 : 2;
            int idxImp = imperial ? 0 : 1;
            int[,] walkingSpeed = { { 2, 3, 5 }, { 3, 5, 8 } };
            int[,] cyclingSpeed = { { 6, 10, 15 }, { 10, 15, 22 } };

            double result = 0;
            if (type == TravelType.Walking)
                result = walkingSpeed[idxImp, idxSpeed];
            else
                result = cyclingSpeed[idxImp, idxSpeed];
            return result;
        }