public static bool RectAndRect(RectCollider rec1, RectCollider rec2) { Rectangle r1 = new Rectangle((int)rec1.gameObj.location.xPoint, (int)rec1.gameObj.location.yPoint, (int)rec1.EdgeHorizontal, (int)rec1.EdgeVertical); Rectangle r2 = new Rectangle((int)rec2.gameObj.location.xPoint, (int)rec2.gameObj.location.yPoint, (int)rec2.EdgeHorizontal, (int)rec2.EdgeVertical); return(r1.IntersectsWith(r2)); }
public static bool CrossCircleAndRectangle(RoundCollider roc, RectCollider rec) { VectorXY v = new VectorXY(Math.Abs(roc.gameObj.location.xPoint - rec.gameObj.location.xPoint), Math.Abs(roc.gameObj.location.yPoint - rec.gameObj.location.yPoint)); VectorXY h = new VectorXY(rec.EdgeHorizontal / 2, rec.EdgeVertical / 2); VectorXY u = v - h; u.vx = (Math.Max(u.vx, 0)); u.vy = (Math.Max(u.vy, 0)); return(u.NormSuquare() - Math.Pow(roc.r, 2) <= 0); }