public void Resolve(Rectangle b) { if (!Collides(b)) return; float xOverlap = Math.Max(0, Math.Min(Max.X, b.Max.X) - Math.Max(Min.X, b.Min.X)); float yOverlap = Math.Max(0, Math.Min(Max.Y, b.Max.Y) - Math.Max(Min.Y, b.Min.Y)); if (xOverlap == 0 || yOverlap == 0) return; Vector2 vector = xOverlap > yOverlap ? new Vector2(0, yOverlap) : new Vector2(xOverlap, 0); if (!Fixed) { Position += vector; } else if (!b.Fixed) { b.Position -= vector; } }
public bool Touches(Rectangle b) { return b.Min.X <= Max.X && Min.X <= b.Max.X && b.Min.Y <= Max.Y && Min.Y <= b.Max.Y; }
public bool Collides(Rectangle b) { return b.Min.X < Max.X && Min.X < b.Max.X && b.Min.Y < Max.Y && Min.Y < b.Max.Y; }