예제 #1
0
        public bool DetectAndVerify(IBall ball)
        {
            if (ball.Boundary.Min.X < 0)
            {
                ball.Boundary.Min = new Vector2(0, ball.Boundary.Min.Y);
                return(ball.Bounce(Edge.Left));
            }

            if (ball.Boundary.Min.X > screen.Width - ball.Boundary.Size.X)
            {
                ball.Boundary.Min = new Vector2(screen.Width - ball.Boundary.Size.X, ball.Boundary.Min.Y);
                return(ball.Bounce(Edge.Right));
            }

            if (ball.Boundary.Min.Y < 0)
            {
                ball.Boundary.Min = new Vector2(ball.Boundary.Min.X, 0);
                return(ball.Bounce(Edge.Top));
            }

            if (ball.Boundary.Min.Y > screen.Height - ball.Boundary.Size.Y)
            {
                ball.Boundary.Min = new Vector2(ball.Boundary.Min.X, screen.Height - ball.Boundary.Size.Y);
                return(ball.Bounce(Edge.Bottom));
            }

            return(false);
        }
예제 #2
0
        public bool DetectAndVerify(IBall ball)
        {
            if (!(ball is IElement ballElement))
            {
                return(false);
            }

            if (ballElement.PosX < 0)
            {
                ballElement.PosX = 0;
                return(ball.Bounce(Edge.Right));
            }

            if (ballElement.PosX > screen.Width - ballElement.Width)
            {
                ballElement.PosX = screen.Width - ballElement.Width;
                return(ball.Bounce(Edge.Left));
            }

            if (ballElement.PosY < 0)
            {
                ballElement.PosY = 0;
                return(ball.Bounce(Edge.Bottom));
            }

            if (ballElement.PosY > screen.Height - ballElement.Height)
            {
                ballElement.PosY = screen.Height - ballElement.Height;
                return(ball.Bounce(Edge.Top));
            }

            return(false);
        }
예제 #3
0
        private bool BounceSmallBall(IBall ball)
        {
            if (XLeftInside && XRightInside && YTopInside && !YBottomInside)
            {
                ball.Bounce(Edge.Bottom);
                return(true);
            }

            if (XLeftInside && XRightInside && !YTopInside && YBottomInside)
            {
                ball.Bounce(Edge.Top);
                return(true);
            }

            if (!XLeftInside && XRightInside && YTopInside && YBottomInside)
            {
                ball.Bounce(Edge.Left);
                return(true);
            }

            if (XLeftInside && !XRightInside && YTopInside && YBottomInside)
            {
                ball.Bounce(Edge.Right);
                return(true);
            }

            return(false);
        }
예제 #4
0
        private bool BounceBigBallLeftOrRight(IBall ball)
        {
            if (Flags.OverlapOutsideRight())
            {
                ball.Bounce(Edge.Right);
                return(true);
            }

            if (Flags.OverlapOutsideLeft())
            {
                ball.Bounce(Edge.Left);
                return(true);
            }
            return(false);
        }
예제 #5
0
        private bool BounceBigBallBottomOrTop(IBall ball)
        {
            if (Flags.OverlapOutsideTop())
            {
                ball.Bounce(Edge.Top);
                return(true);
            }

            if (Flags.OverlapOutsideBottom())
            {
                ball.Bounce(Edge.Bottom);
                return(true);
            }
            return(false);
        }
예제 #6
0
        private bool BallBounceFromVertEdge(IBall ball)
        {
            if (Flags.XLeftInside && !Flags.XRightInside)
            {
                ball.Bounce(Edge.Left);
                return(true);
            }

            if (!Flags.XLeftInside && Flags.XRightInside)
            {
                ball.Bounce(Edge.Right);
                return(true);
            }

            return(false);
        }
예제 #7
0
        private bool BallBounceFromHorizEdge(IBall ball)
        {
            if (Flags.YTopInside && !Flags.YBottomInside)
            {
                ball.Bounce(Edge.Top);
                return(true);
            }

            if (!Flags.YTopInside && Flags.YBottomInside)
            {
                ball.Bounce(Edge.Bottom);
                return(true);
            }

            return(false);
        }