Exemplo n.º 1
0
 public static bool Collide(RectangleCollisionShape s1, RectangleCollisionShape s2)
 {
     return s1.Shape.Intersects(s2.Shape);
 }
Exemplo n.º 2
0
        public static bool Collide(RectangleCollisionShape s1, CircleCollisionShape s2)
        {
            float circleDistanceX = Math.Abs(s2.Center.X - s1.Shape.X);
            float circleDistanceY = Math.Abs(s2.Center.Y - s1.Shape.Y);

            if (circleDistanceX > (s1.Shape.Width / 2 + s2.Radius)) { return false; }
            if (circleDistanceY > (s1.Shape.Height / 2 + s2.Radius)) { return false; }

            if (circleDistanceX <= (s1.Shape.Width / 2)) { return true; }
            if (circleDistanceY <= (s1.Shape.Height / 2)) { return true; }

            double cornerDistance_sq = Math.Pow((circleDistanceX - s1.Shape.Width / 2), 2) +
                                 Math.Pow((circleDistanceY - s1.Shape.Height / 2), 2);

            return cornerDistance_sq < Math.Pow(s2.Radius, 2);
        }
Exemplo n.º 3
0
 public static bool Collide(RectangleCollisionShape s1, CompoundCollisionShape s2)
 {
     foreach (ICollisionShape c2 in s2.Shapes)
     {
         if (Collide(s1, c2))
             return true;
     }
     return false;
 }