コード例 #1
0
        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;
            }
        }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }