Exemple #1
0
        public override void Paint()
        {
            base.Paint();

            this.isLeftSide = this.position.x < 0;

            this.lastVelocity = new Velocity() { x = 0, y = 0 };

            TranslateTransform translateTransform = new TranslateTransform()
            {
                X = this.position.x,
                Y = this.position.y,
            };

            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            if (isLeftSide)
            {
                mySolidColorBrush.Color = Color.FromArgb(50, 124, 252, 0);
            }
            else
            {
                mySolidColorBrush.Color = Color.FromArgb(50, 255, 215, 0);
            }

            this.ellipse.Fill = mySolidColorBrush;
            this.ellipse.Width = this.size.width;
            this.ellipse.Height = this.size.height;
            this.ellipse.RenderTransform = translateTransform;
            this.ellipse.ManipulationDelta += ellipse_ManipulationDelta;
            this.ellipse.ManipulationMode = Windows.UI.Xaml.Input.ManipulationModes.All;
            this.ellipse.Tapped += ellipse_Tapped;

            GameContainer.mainGrid.Children.Add(this.ellipse);

            miniPlayer = new MiniPlayerEntity()
            {
                position = new Position()
                {
                    x = this.isLeftSide ? GlobalMethods.FromCornerXToMiddleXAxis((float)(GlobalVariables.fieldWidth - GlobalVariables.playerFieldWidth - 200)) :
                                           GlobalMethods.FromCornerXToMiddleXAxis((float)(GlobalVariables.playerFieldWidth + 200)),
                    y = this.position.y,
                },

                size = new Pongaline.Classes.Size
                {
                    height = 100,
                    width = 30,
                },

                imageURI = this.isLeftSide ? new Uri("ms-appx:///Assets/DontSueUs/yoshiRight.png") : new Uri("ms-appx:///Assets/DontSueUs/yoshiLeft.png"),

            };

            GameContainer.AddEntity(miniPlayer);
        }
Exemple #2
0
        void ellipse_ManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
        {
            TranslateTransform imageTransform = this.image.RenderTransform as TranslateTransform;
            TranslateTransform ellipseTransform = this.ellipse.RenderTransform as TranslateTransform;

            this.lastVelocity = new Velocity()
            {
                x = (float)e.Delta.Translation.X,
                y = (float)e.Delta.Translation.Y,
            };

            var newX = imageTransform.X + e.Delta.Translation.X;
            var newY = imageTransform.Y + e.Delta.Translation.Y;

            if (isLeftSide && newX > GlobalMethods.FromCornerXToMiddleXAxis(0)
                           && newX < GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.playerFieldWidth))
            {
                ellipseTransform.X = imageTransform.X = newX;
            }
            else if (isLeftSide)
            {
                double distanceRight = Math.Abs(newX - GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.playerFieldWidth));
                double distanceLeft = Math.Abs(newX - GlobalMethods.FromCornerXToMiddleXAxis(0));

                ellipseTransform.X = imageTransform.X = distanceRight < distanceLeft ?
                    GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.playerFieldWidth) :
                    GlobalMethods.FromCornerXToMiddleXAxis(0);
            }

            if (!isLeftSide && newX > GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth - GlobalVariables.playerFieldWidth) &&
                               newX < GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth))
            {
                ellipseTransform.X = imageTransform.X = newX;
            }
            else if (!isLeftSide)
            {
                double distanceRight = Math.Abs(newX - GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth));
                double distanceLeft = Math.Abs(newX - GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth - GlobalVariables.playerFieldWidth));

                ellipseTransform.X = imageTransform.X = distanceRight < distanceLeft ?
                    GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth) :
                    GlobalMethods.FromCornerXToMiddleXAxis(GlobalVariables.fieldWidth - GlobalVariables.playerFieldWidth);
            }

            if (newY > GlobalMethods.FromCornerYToMiddleYAxis(0) &&
                newY < GlobalMethods.FromCornerYToMiddleYAxis(GlobalVariables.fieldHeight))
            {
                ellipseTransform.Y = imageTransform.Y = newY;
            }
            else
            {
                ellipseTransform.Y = imageTransform.Y = newY > 0 ?
                    GlobalMethods.FromCornerYToMiddleYAxis(GlobalVariables.fieldHeight) :
                    GlobalMethods.FromCornerYToMiddleYAxis(0);
            }

            this.position.x = (float)ellipseTransform.X;
            this.position.y = (float)ellipseTransform.Y;
            this.miniPlayer.position.y = this.position.y;
            (this.miniPlayer.image.RenderTransform as TranslateTransform).Y = this.position.y;
        }