public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { //Side walls if (b.X == -GameConstants.WallDefaultSize) { if (a.X - a.Width < b.X + b.Width / 2) { return(true); } } else if (b.X == 500) { if (a.X + a.Width > b.X) { return(true); } } //Paddles if (a.X < b.X + b.Width && a.X > b.X && a.Y + a.Height / 2 > b.Y - b.Height / 2 && b.Y == 860) { return(true); } else if (a.X < b.X + b.Width && a.X > b.X && a.Y - a.Height / 2 < b.Y + b.Height / 2 && b.Y < 450) { return(true); } //Goal walls if (b.Y == 900) { if (a.Y + a.Height / 2 > b.Y) { return(true); } } else if (b.Y == -GameConstants.WallDefaultSize) { if (a.Y - a.Height / 2 < b.Y + b.Height / 2) { return(true); } } //Paddles // else // { // } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { MyPoint topLeftPoint = new MyPoint(a.X, a.Y); MyPoint topRightPoint = new MyPoint(a.X + a.Width, a.Y); MyPoint bottomLeftPoint = new MyPoint(a.X, a.Y + a.Height); MyPoint bottomRightPoint = new MyPoint(a.X + a.Width, a.Y + a.Height); if (checkCollision(topLeftPoint, b)) { return(true); } if (checkCollision(topRightPoint, b)) { return(true); } if (checkCollision(bottomLeftPoint, b)) { return(true); } if (checkCollision(bottomRightPoint, b)) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return(a.X + a.Width > b.X && a.Y < b.Y + b.Height && a.X < b.X + b.Width && a.Y + a.Height > b.Y); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { Rectangle aRect = new Rectangle((int)a.X, (int)a.Y, a.Width, a.Height); Rectangle bRect = new Rectangle((int)b.X, (int)b.Y, b.Width, b.Height); return(aRect.Intersects(bRect)); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { Rectangle recA = new Rectangle(Convert.ToInt32(a.X), Convert.ToInt32(a.Y), a.Width, a.Height); Rectangle recB = new Rectangle(Convert.ToInt32(b.X), Convert.ToInt32(b.Y), b.Width, b.Height); return(recA.Intersects(recB)); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return((a.X <= b.X + b.Width && a.Y + a.Height >= b.Y && a.Y <= b.Y + b.Height && a.X + a.Width >= b.X) || (a.Y + a.Height >= b.Y && a.X + a.Width >= b.X && a.X <= b.X + b.Width && a.Y <= b.Y + b.Height) || (a.X + a.Width >= b.X && a.Y + a.Height >= b.Y && a.Y <= b.Y + b.Height && a.X <= b.X + b.Width) || (a.Y <= b.Y + b.Height && a.X + a.Width >= b.X && a.X <= b.X + b.Width && a.Y + a.Height >= b.Y)); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { PointF upperLeftCorner = new PointF(a.X, a.Y); PointF upperRightCorner = new PointF(a.X + a.Width, a.Y); PointF lowerLeftCorner = new PointF(a.X, a.Y + a.Height); PointF lowerRightCorner = new PointF(a.X + a.Width, a.Y + a.Height); PointF xAxisPoints = new PointF(b.X, b.X + b.Width); PointF yAxisPoints = new PointF(b.Y, b.Y + b.Height); if (DetectCollision(upperLeftCorner, xAxisPoints, yAxisPoints)) { return(true); } if (DetectCollision(upperRightCorner, xAxisPoints, yAxisPoints)) { return(true); } if (DetectCollision(lowerLeftCorner, xAxisPoints, yAxisPoints)) { return(true); } if (DetectCollision(lowerRightCorner, xAxisPoints, yAxisPoints)) { return(true); } return(false); }
/// <summary> /// Checks if boundbox of object a overlaps with object b. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { // return true if overlaps , false otherwise ... Vector2[] firstObj = { new Vector2(a.X, a.Y), new Vector2(a.X, a.Y + a.Height), new Vector2(a.X + a.Width, a.Y + a.Height), new Vector2(a.X + a.Width, a.Y) }; foreach (Vector2 temp in firstObj) { if (temp.X >= b.X && temp.X <= b.X + b.Width && temp.Y >= b.Y && temp.Y <= b.Y + b.Height) { return(true); } } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { bool vertical = a.Y <b.Y && a.Y + a.Height> b.Y || a.Y > b.Y && a.Y < b.Y + b.Height; bool horizontal = a.X <b.X && a.X + a.Width> b.X || a.X > b.X && a.X < b.X + b.Width; return(vertical && horizontal); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return(a.X + a.Width < b.X || b.X + b.Width < a.X || a.Y + a.Height < b.Y || b.Y + b.Height < a.Y ? false : true); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { Ball ball = (Ball)a; if (b.ToString().Contains("Wall")) { Wall wall = (Wall)b; if (wall.X != 0) { if (wall.X < 0) { if ((ball.X - 5f) <= 0) { return(true); //5f should be float.Epsilon on a high-end computer } //(because Update method is called more frequently), works like this on my laptop } else { if ((wall.X - ball.X) <= 40f) { return(true); //40f = Ball width } } } else { if (wall.Y < 0) { if (ball.Y - float.Epsilon + 20f <= 0) { return(true); } } else { if (900f - ball.Y <= float.Epsilon) { return(true); // 900f height of the screen } } } } else { Paddle paddle = (Paddle)b; if (((paddle.X + paddle.Width) >= ball.X && (paddle.X) <= ball.X) && paddle.Name.Equals("PaddleTop") && ball.Y - 20f <= 0) { return(true); } if ((paddle.X + paddle.Width >= ball.X && paddle.X <= ball.X) && paddle.Name.Equals("PaddleBottom") && 840f - ball.Y <= 0) { return(true); } } return(false); }
private static bool checkCollision(MyPoint point, IPhysicalObject2D b) { if ((b.X <= point.X && point.X <= (b.X + b.Width)) && (b.Y <= point.Y && point.Y <= (b.Y + b.Height))) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { IPhysicalObject2D narrow, wide, tall, small; if (a.Width > b.Width) { wide = a; narrow = b; } else { wide = b; narrow = a; } if (a.Height > b.Height) { tall = a; small = b; } else { tall = b; small = a; } if (narrow.X >= wide.X) { if (narrow.X - wide.X > wide.Width) { return(false); } } else if (narrow.X < wide.X) { if (wide.X - narrow.X > narrow.Width) { return(false); } } if (tall.Y >= small.Y) { if (tall.Y - small.Y > small.Height) { return(false); } } else if (tall.Y < small.Y) { if (small.Y - tall.Y > tall.Height) { return(false); } } return(true); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { Ball ball = (Ball)a; if (b.Width == GameConstants.PaddleDefaultWidth) { Paddle paddle = (Paddle)b; if (paddle.name.Equals("Bottom")) { if (Math.Abs(ball.Y - paddle.Y + paddle.Height) < 5f && (ball.X > paddle.X && ball.X < paddle.X + paddle.Width)) { return(true); } } if (paddle.name.Equals("Top")) { if ((Math.Abs(ball.Y - paddle.Y - paddle.Height) < 10f) && (ball.X > paddle.X && ball.X < paddle.X + paddle.Width)) { return(true); } } } else if (Math.Abs(b.X + GameConstants.WallDefaultSize) < 0.0001) { Wall leftWall = (Wall)b; if (Math.Abs(leftWall.X + GameConstants.WallDefaultSize - ball.X - ball.Width) < 5f) { return(true); } } else if (Math.Abs(b.Y) < 0.0001) { Wall rightWall = (Wall)b; if (Math.Abs(rightWall.X - ball.X - ball.Width) < 5f) { return(true); //High performance graphics processor doesn't support Reach! } } else if (Math.Abs(b.X) < 0.0001) { Wall bottomWall = (Wall)b; if (Math.Abs(bottomWall.Y - ball.Y) < 4f) { return(true); } } else { Wall topWall = (Wall)b; if (Math.Abs(topWall.Y - ball.Y) < 4f) { return(true); } } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { bool xOverlap = ValueInRange(a.X, b.X, b.X + b.Width) || ValueInRange(b.X, a.X, a.X + a.Width); bool yOverlap = ValueInRange(a.Y, b.Y, b.Y + b.Height) || ValueInRange(b.Y, a.Y, a.Y + a.Height); return(xOverlap && yOverlap); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { Rectangle recA = new Rectangle((int)a.X, (int)a.Y, a.Width, a.Height); Rectangle recB = new Rectangle((int)b.X, (int)b.Y, b.Width, b.Height); if (recA.Intersects(recB)) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { if ((a.X >= b.X && a.X <= b.X + b.Width && a.Y >= b.Y && a.Y <= b.Y + b.Height) || (b.X >= a.X && b.X <= a.X + a.Width && b.Y >= a.Y && b.Y <= a.Y + a.Height) || (a.X + a.Width >= b.X && a.X + a.Width <= b.X + b.Width && a.Y + a.Height >= b.Y && a.Y + a.Height <= b.Y + b.Height) || (b.X + b.Width >= a.X && b.X + b.Width <= a.X + a.Width && b.Y + b.Height >= a.Y && b.Y + b.Height <= a.Y + a.Height)) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { if (a.X <= b.X + b.Width && a.X + a.Width > b.X && a.Y < b.Y + b.Height && a.Height + a.Y > b.Y) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { if (a.X < (b.X + b.Width) && (a.X + a.Width) > b.X && a.Y < (b.Y + b.Height) && (a.Y + a.Height) > b.Y) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { if (a != null && b != null) { Rectangle r1 = new Rectangle((int)a.X, (int)a.Y, a.Width, a.Height); Rectangle r2 = new Rectangle((int)b.X, (int)b.Y, b.Width, b.Height); if (r1.Intersects(r2)) { return(true); } } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { /* * //TODO: popraviti grešku kad se loptica preklopi sa strane s nekim od reketa (paddle)... za svaki IPhysicalObject2D provjeriti što je * if ((int)a.X == (int)b.X + (int)b.Width || (int)a.X + (int)a.Width == (int)b.X || (int)a.Y == (int)b.Y + (int)b.Height || (int)a.Y + (int)a.Height == (int)b.Y) * { * return true; * } * return false; */ return((a.X <= b.X + b.Width && a.Y + a.Height >= b.Y && a.Y <= b.Y + b.Height && a.X + a.Width >= b.X) || (a.Y + a.Height >= b.Y && a.X + a.Width >= b.X && a.X <= b.X + b.Width && a.Y <= b.Y + b.Height) || (a.X + a.Width >= b.X && a.Y + a.Height >= b.Y && a.Y <= b.Y + b.Height && a.X <= b.X + b.Width) || (a.Y <= b.Y + b.Height && a.X + a.Width >= b.X && a.X <= b.X + b.Width && a.Y + a.Height >= b.Y)); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { BoundingBox bb1 = new BoundingBox(new Vector3(a.X, a.Y, 0), new Vector3(a.X + a.Width, a.Y + a.Height, 0)); BoundingBox bb2 = new BoundingBox(new Vector3(b.X, b.Y, 0), new Vector3(b.X + b.Width, b.Y + b.Height, 0)); if (bb1.Intersects(bb2)) { return(true); } else { return(false); } }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { float x1a, y1a, x2a, y2a; float x1b, y1b, x2b, y2b; x1a = a.X; x2a = a.X + a.Width; y1a = a.Y; y2a = a.Y + a.Height; x1b = b.X; x2b = b.X + b.Width; y1b = b.Y; y2b = b.Y + b.Height; if (x1a < x2b && x2a > x1b && y1a < y2b && y2a > y1b) { return(true); } return(false); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { if (a.X > b.X + b.Width) { return(false); } if (a.X + a.Width < b.X) { return(false); } if (a.Y > b.Y + b.Height) { return(false); } if (a.Y + a.Height < b.Y) { return(false); } return(true); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { // return true if overlaps , false otherwise ... if (a.Y > b.Y + b.Height) { return(false); } if (a.Y + a.Height < b.Y) { return(false); } if (a.X > b.X + b.Width) { return(false); } if (a.X + a.Width < b.X) { return(false); } return(true); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return ((a.X <= b.X + b.Width && a.X >= b.X || a.X + a.Width >= b.X && a.X + a.Width <= b.X + b.Width || !(a.X > b.X ^ a.X + a.Width < b.X + b.Width)) && (a.Y <= b.Y + b.Height && a.Y >= b.Y || a.Y + a.Height >= b.Y && a.Y + a.Height <= b.Y + b.Height || !(a.Y > b.Y ^ a.Y + a.Height < b.Y + b.Height))); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return(!(a.X + a.Width < b.X) && !(b.X + b.Width < a.X) && !(a.Y + a.Height < b.Y) && !(b.Y + b.Height < a.Y)); }
/// <summary> /// Checks for AABB collisions (overlapping) /// </summary> /// <param name="a">First object</param> /// <param name="b">Second object</param> /// <returns></returns> public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return((a.X < b.X + b.Width) && (a.X + a.Width > b.X) && (a.Y < b.Y + b.Height) && (a.Height + a.Y > b.Y)); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { return(a.X - b.Width < b.X && b.X < a.X + a.Width && a.Y - b.Height < b.Y && b.Y < a.Y + a.Height); }
public static bool Overlaps(IPhysicalObject2D a, IPhysicalObject2D b) { //TODO return(false); }