Beispiel #1
0
        public async Task AnimateAppleWhooshAsync(DraggableImage apple)
        {
            var ax = AppleHelpers.GetLeft(apple);
            var ay = AppleHelpers.GetTop(apple);
            var bx = AppleHelpers.GetLeft(BasketBottomArea) + RND.Next() % (BasketBottomArea.Width - apple.Width);
            var by = AppleHelpers.GetTop(BasketBottomArea) + RND.Next() % (BasketBottomArea.Height - apple.Height);

            //Canvas.SetLeft(apple, bx); Canvas.SetTop(apple, by);
            AbsoluteLayout.SetLayoutBounds(apple, new Rectangle(bx, by, apple.Width, apple.Height));
            SetZIndex(apple, 1);
            var sb = new StoryBoard(); //From = ax - bx, From = ay - by
            var an = new TranslateToAnimation {
                TranslateX = 0, TranslateY = 0, Duration = (200).ToString()
            };

            sb.Target = apple;
            sb.Animations.Add(an);
            await sb.PlayAsync();
        }
Beispiel #2
0
        private void CreateAppleImages(List <Position> positions)
        {
            foreach (var apple in AllApples)
            {
                BasketCanvas.Children.Remove(apple);
            }

            foreach (var position in positions)
            {
                var apple = new DraggableImage()
                {
                    Source = appleImage, WidthRequest = 80, HeightRequest = 80
                };
                // apple.RenderTransform = new CompositeTransform() { Rotation = position.Item3, CenterX = 40, CenterY = 40 };
                apple.Rotation = position.R;
                BasketCanvas.Children.Add(apple);
                AbsoluteLayout.SetLayoutBounds(apple, new Rectangle(position.X, position.Y, 80, 80));
                //Canvas.SetLeft(apple, position.Item1);Canvas.SetTop(apple, position.Item2);
                SetZIndex(apple, position.Z);
            }
        }
Beispiel #3
0
        private async Task ImageTapped(DraggableImage apple)
        {
            if (!FreeApples.Contains(apple))
            {
                return;
            }
            highestZIndex += 1;
            SetZIndex(apple, highestZIndex);
            var endpt = await DragAsync(apple, Point.Zero, BasketCatchmentArea.Bounds);

            if (!BasketCatchmentArea.Bounds.Contains(endpt))
            {
                return;
            }

            var soundTask   = Sounds.WhooshSound.PlayAsync();
            var animateTask = AnimateAppleWhooshAsync(apple);
            await Task.WhenAll(soundTask, animateTask);

            if (FreeApples.Count() == 0)
            {
                EndGameAsync().FireAndForget();
            }
        }