public override bool IsCollision(Collision collision) { if (collision.GetType() == typeof(BoxCollision)) { return(GetMacroCollisionRect().IsMacroCollision(collision.GetMacroCollisionRect())); } else if (collision.GetType() == typeof(CircleCollision)) { CircleCollision circle = (CircleCollision)collision; float cX = circle.Center().X; float cY = circle.Center().Y; if (cX < Position.X) { cX = Position.X; } else if (cX > (Position.X + Size.X)) { cX = Position.X + Size.X; } if (cY < Position.Y) { cY = Position.Y; } else if (cY > (Position.Y + Size.Y)) { cY = Position.Y + Size.Y; } if ((circle.Center() - new VectorF(cX, cY)).Length() < circle.Radius) { return(true); } return(false); } else { return(collision.IsCollision(this)); } }
public override bool IsCollision(Collision collision) { if (GetMacroCollisionRect().IsMacroCollision(collision.GetMacroCollisionRect()) == false) { return(false); } if (collision.GetType() == typeof(PolygonCollision)) { PolygonCollision poly = (PolygonCollision)collision; for (int i = 0, p = Points.Count - 1; i < Points.Count; i++) { for (int j = 0, q = poly.Points.Count - 1; j < poly.Points.Count; j++) { if (SimpleGeometry.IsIntersection(Points[i] + Position, Points[p] + Position, poly.Points[j] + poly.Position, poly.Points[q] + poly.Position)) { return(true); } q = j; } p = i; } return(IsPointInPoly(poly.Points[0] + poly.Position) || poly.IsPointInPoly(Points[0] + Position)); } else if (collision.GetType() == typeof(BoxCollision)) { BoxCollision box = (BoxCollision)collision; for (int i = 0, j = Points.Count - 1; i < Points.Count; i++) { if (SimpleGeometry.IsIntersection(Points[i] + Position, Points[j] + Position, box.Position, box.Position + new VectorF(box.Size.X, 0)) || SimpleGeometry.IsIntersection(Points[i] + Position, Points[j] + Position, box.Position + new VectorF(box.Size.X, 0), box.Position + box.Size) || SimpleGeometry.IsIntersection(Points[i] + Position, Points[j] + Position, box.Position + box.Size, box.Position + new VectorF(0, box.Size.Y)) || SimpleGeometry.IsIntersection(Points[i] + Position, Points[j] + Position, box.Position + new VectorF(0, box.Size.Y), box.Position)) { return(true); } j = i; } return(IsPointInPoly(box.Position) || (((Points[0].X + Position.X) > box.Position.X) && ((Points[0].X + Position.X) < (box.Position.X + box.Size.X)) && ((Points[0].Y + Position.Y) > box.Position.Y) && ((Points[0].Y + Position.Y) < (box.Position.Y + box.Size.Y)))); } else if (collision.GetType() == typeof(CircleCollision)) { CircleCollision circle = (CircleCollision)collision; for (int i = 0, j = Points.Count - 1; i < Points.Count; i++) { if (SimpleGeometry.IsSegmentIntersectsWithCircle(circle.Center(), circle.Radius, Points[i] + Position, Points[j] + Position)) { return(true); } j = i; } return(IsPointInPoly(circle.Center()) || ((Points[0] + Position - circle.Center()).Length() < circle.Radius)); } else { return(collision.IsCollision(this)); } }