Ejemplo n.º 1
0
        private bool PointInRectangular(GameStructure.Point point, GameStructure.Rectangle rectangle)
        {
            bool betweenXLine = (rectangle.PositionX <= point.PositionX) && (point.PositionX <= rectangle.PositionX + rectangle.Width);
            bool betweenYLine = (rectangle.PositionY <= point.PositionY) && (point.PositionY <= rectangle.PositionY + rectangle.Height);

            return(betweenXLine && betweenYLine);
        }
Ejemplo n.º 2
0
        public bool CircleInRect(GameStructure.Circle circle, GameStructure.Rectangle rectangle)
        {
            GameStructure.Point lefmost    = new GameStructure.Point(circle.PositionX - circle.Radius, circle.PositionY);
            GameStructure.Point rightmost  = new GameStructure.Point(circle.PositionX + circle.Radius, circle.PositionY);
            GameStructure.Point topmost    = new GameStructure.Point(circle.PositionX, circle.PositionY - circle.Radius);
            GameStructure.Point bottommost = new GameStructure.Point(circle.PositionX, circle.PositionY + circle.Radius);

            List <GameStructure.Point> cornerPoints = new List <GameStructure.Point>();

            cornerPoints.Add(lefmost);
            cornerPoints.Add(rightmost);
            cornerPoints.Add(topmost);
            cornerPoints.Add(bottommost);

            foreach (GameStructure.Point point in cornerPoints)
            {
                if (PointInRectangular(point, rectangle))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
 private bool BallInPlayerBar(Player player)
 {
     GameStructure.Circle    circle    = new GameStructure.Circle(GameStructure.Ball.PositionX, GameStructure.Ball.PositionY, GameStructure.Ball.Radius);
     GameStructure.Rectangle rectangle = new GameStructure.Rectangle(player.PositionX, player.PositionY, player.Height, player.Width);
     return(CollisionDetector.CircleInRect(circle, rectangle));
 }