Advertisement
Tyler_Elric

pixel-collider.cs

Dec 12th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. Rectangle a = Bounds, b = level.Bounds;//, inter = new Rectangle();
  2.                 a.Y += a.Height - feet_size;
  3.                 a.Height = feet_size;
  4.                 if (!(a.Intersects(b)))
  5.                     return false;
  6.                 /*inter.X = Math.Max(a.X, b.X);
  7.                 inter.Y = Math.Max(a.Y, b.Y);
  8.                 inter.Width = Math.Min(a.Width, b.Width);
  9.                 inter.Height = Math.Min(a.Height, b.Height);
  10.                 Rectangle a_src = source, b_src = level.source;
  11.                 b_src.Width = a_src.Width = inter.Width;
  12.                 b_src.Height = a_src.Height = inter.Height;
  13.                 if (a.Y > b.Y)
  14.                     b_src.Y += a.Y - b.Y;
  15.                 if (a.X > b.X)
  16.                     b_src.X += a.X - b.X;
  17.                 else
  18.                     a_src.X += b.X - a.X;
  19.                 a_src.Y += Height - feet_size;*/
  20.                 Rectangle a_src = new Rectangle(), b_src = new Rectangle();
  21.                 a_src.X = sprite * Width;
  22.                 a_src.Y = (bank * Height) + (Height - feet_size);
  23.                 b_src.X = Convert.ToInt32(Math.Max(level.position.X, position.X));
  24.                 b_src.Y = Convert.ToInt32(Math.Max(level.position.Y, position.Y));
  25.                 b_src.Y -= Convert.ToInt32(Math.Min(level.position.Y, position.Y));
  26.                 b_src.Width = a_src.Width = Math.Min(Width, level.Width);
  27.                 b_src.Width = Math.Min(b_src.Width - b_src.X, b_src.Width + b_src.X);
  28.                 b_src.Height = a_src.Height = feet_size;
  29.                 Color[] bitsA = new Color[a_src.Width * a_src.Height];
  30.                 Color[] bitsB = new Color[b_src.Width * b_src.Height];
  31.                 src.GetData(0, a_src, bitsA, 0, bitsA.Count());
  32.                 level.src.GetData(0, b_src, bitsB, 0, bitsB.Count());
  33.                 int ux = Math.Min(a_src.Width, b_src.Width),
  34.                     uy = Math.Min(a_src.Height, b_src.Height);
  35.                 for (int y = 0; y < uy; y++)
  36.                 {
  37.                     int a_point = y * a_src.Width,
  38.                         b_point = y * b_src.Width;
  39.                     for (int x = 0; x < ux; x++)
  40.                     {
  41.                         Color ca = bitsA[a_point + x];
  42.                         Color cb = bitsB[b_point + x];
  43.                         if (ca.A > 0 && cb.A > 0)
  44.                             return true;
  45.                     }
  46.                 }
  47.                 return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement