Example #1
0
 public DIR DirectionCollision(MyObject _Obj)
 {
     if (RECT.Intersects(_Obj.RECT))
     {
         float top   = Math.Abs(RECT.Top - _Obj.RECT.Bottom);
         float botom = Math.Abs(RECT.Bottom - _Obj.RECT.Top);
         float left  = Math.Abs(RECT.Left - _Obj.RECT.Right);
         float right = Math.Abs(RECT.Right - _Obj.RECT.Left);
         float rs    = Math.Min(Math.Min(right, left), Math.Min(top, botom));
         if (rs == top)
         {
             return(DIR.TOP);
         }
         if (rs == botom)
         {
             return(DIR.BOTTOM);
         }
         if (rs == left)
         {
             return(DIR.LEFT);
         }
         if (rs == right)
         {
             return(DIR.RIGHT);
         }
     }
     return(DIR.NONE);
 }
Example #2
0
        public eGDirectCollision DirectionCollision(GObject Obj)
        {
            if (RECT.Intersects(Obj.RECT))
            {
                float top   = Math.Abs(RECT.Top - Obj.RECT.Bottom);
                float botom = Math.Abs(RECT.Bottom - Obj.RECT.Top);
                float left  = Math.Abs(RECT.Left - Obj.RECT.Right);
                float right = Math.Abs(RECT.Right - Obj.RECT.Left);
                float rs    = Math.Min(Math.Min(right, left), Math.Min(top, botom));

                if (rs == top)
                {
                    return(eGDirectCollision.TOP);
                }
                if (rs == botom)
                {
                    return(eGDirectCollision.BOT);
                }
                if (rs == left)
                {
                    return(eGDirectCollision.LEFT);
                }
                if (rs == right)
                {
                    return(eGDirectCollision.RIGHT);
                }
            }
            return(eGDirectCollision.NONE);
        }