Exemple #1
0
 /// <summary>
 /// 判定指定的两张图片之间是否产生了碰撞
 /// </summary>
 ///
 /// <param name="src"></param>
 /// <param name="x1"></param>
 /// <param name="y1"></param>
 /// <param name="dest"></param>
 /// <param name="x2"></param>
 /// <param name="y2"></param>
 /// <returns></returns>
 public bool isPixelCollide(LImage src, float x1, float y1, LImage dest,
         float x2, float y2)
 {
     float width1 = x1 + src.GetWidth() - 1, height1 = y1 + src.GetHeight()
             - 1, width2 = x2 + dest.GetWidth() - 1, height2 = y2
             + dest.GetHeight() - 1;
     int xstart = (int)Loon.Utils.MathUtils.Max(x1, x2), ystart = (int)Loon.Utils.MathUtils.Max(y1, y2), xend = (int)Loon.Utils.MathUtils.Min(width1, width2), yend = (int)Loon.Utils.MathUtils.Min(height1, height2);
     int toty = Loon.Utils.MathUtils.Abs(yend - ystart);
     int totx = Loon.Utils.MathUtils.Abs(xend - xstart);
     for (int y = 1; y < toty - 1; y++)
     {
         int ny = Loon.Utils.MathUtils.Abs(ystart - (int)y1) + y;
         int ny1 = Loon.Utils.MathUtils.Abs(ystart - (int)y2) + y;
         for (int x = 1; x < totx - 1; x++)
         {
             int nx = Loon.Utils.MathUtils.Abs(xstart - (int)x1) + x;
             int nx1 = Loon.Utils.MathUtils.Abs(xstart - (int)x2) + x;
             try
             {
                 if (((src.GetPixel(nx, ny).PackedValue != LSystem.TRANSPARENT))
                         && ((dest.GetPixel(nx1, ny1).PackedValue != LSystem.TRANSPARENT)))
                 {
                     return true;
                 }
             }
             catch (Exception e)
             {
                 Loon.Utils.Debugging.Log.Exception(e);
             }
         }
     }
     return false;
 }