Exemple #1
0
        private void Image_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            Image         imgAux          = sender as Image;
            var           image_Transform = (CompositeTransform)imgAux.RenderTransform;
            InertialImage imagenActual    = images.Find(i => i.GetPosX() == image_Transform.TranslateX && i.GetPosY() == image_Transform.TranslateY);

            imagenActual.XInertia = imagenActual.YInertia = false;
            //If a player scores, the ball disapears
            //Since you cannot remove the ball dynamically from the grid, we set opacity to 0
            if (imagenActual.isGoal)
            {
                images.Remove(imagenActual);
                imagenActual.GetImage().Opacity = 0;
            }
        }
Exemple #2
0
        private void Grid_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            //Creates an Inertial Ball
            //Inertial ball is an object that contains an Image, with several attributes
            //Inertial ball object can be found in /Objects/InertialImage.cs
            var inertialImage = new InertialImage();
            var image         = inertialImage.GetImage();

            image.ManipulationStarted   += Image_ManipulationStarted;
            image.ManipulationDelta     += Image_ManipulationDelta;
            image.ManipulationCompleted += Image_ManipulationCompleted;
            grid.Children.Add(image);
            var compositeTransform = image.RenderTransform as CompositeTransform;

            compositeTransform.TranslateX = e.GetPosition(grid).X - grid.ActualWidth / 2;
            compositeTransform.TranslateY = e.GetPosition(grid).Y - grid.ActualHeight / 2;
            images.Add(inertialImage);
        }
Exemple #3
0
        private void Image_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            Image imgAux          = sender as Image;
            var   image_Transform = (CompositeTransform)imgAux.RenderTransform;
            //Finds the inertial image based on its position
            InertialImage imagenActual = images.Find(i => i.GetPosX() == image_Transform.TranslateX && i.GetPosY() == image_Transform.TranslateY);
            var           source       = (FrameworkElement)e.OriginalSource;
            bool          xInertial    = imagenActual.XInertia;
            bool          yInertial    = imagenActual.YInertia;

            if (source != null)
            {
                //Code to execute when the ball is droped from the cursor
                if (e.IsInertial)
                {
                    //Conditions to make the ball bounce
                    if (Math.Abs(image_Transform.TranslateX) + imagenActual.GetImage().ActualWidth >= xGrid && Math.Abs(image_Transform.TranslateY) + imagenActual.GetImage().ActualHeight >= yGrid * 0.5)
                    {
                        xInertial = !xInertial;
                    }
                    if (Math.Abs(image_Transform.TranslateY) + imagenActual.GetImage().ActualHeight >= yGrid)
                    {
                        yInertial = !yInertial;
                    }
                    //Condition if the player scores
                    if (Math.Abs(image_Transform.TranslateX) + imagenActual.GetImage().ActualWidth >= xGrid && Math.Abs(image_Transform.TranslateY) + imagenActual.GetImage().ActualHeight < yGrid * 0.5)
                    {
                        try
                        {
                            Goal(image_Transform.TranslateX);
                            e.Complete();
                            imagenActual.isGoal = true;
                        }
                        catch (Exception) { }
                    }
                    //Condition for de slidebars
                    if (elements.Count > 0)
                    {
                        foreach (var element in elements)
                        {
                            var element_Transform = (CompositeTransform)element.RenderTransform;
                            //Condition that detects the bar, and makes the ball bounce if it tries going through
                            if (Math.Abs(image_Transform.TranslateX) > Math.Abs(element_Transform.TranslateX)
                                &&
                                element_Transform.TranslateX * image_Transform.TranslateX > 0
                                &&
                                image_Transform.TranslateY <= (element_Transform.TranslateY + element_Transform.CenterY) * element_Transform.ScaleY
                                &&
                                image_Transform.TranslateY > (element_Transform.TranslateY - element_Transform.CenterY) * element_Transform.ScaleY
                                )
                            {
                                xInertial = !xInertial;
                            }
                        }
                    }
                }
            }
            imagenActual.XInertia = xInertial;
            imagenActual.YInertia = yInertial;

            //Directions of the ball based on the bounce results ahead
            if (!xInertial && yInertial)
            {
                image_Transform.TranslateX += e.Delta.Translation.X;
                image_Transform.TranslateY -= e.Delta.Translation.Y;
            }
            else if (xInertial && !yInertial)
            {
                image_Transform.TranslateX -= e.Delta.Translation.X;
                image_Transform.TranslateY += e.Delta.Translation.Y;
            }
            else if (xInertial && yInertial)
            {
                image_Transform.TranslateX -= e.Delta.Translation.X;
                image_Transform.TranslateY -= e.Delta.Translation.Y;
            }
            else
            {
                image_Transform.TranslateX += e.Delta.Translation.X;
                image_Transform.TranslateY += e.Delta.Translation.Y;
            }
        }