All pastes #732625 Raw Edit

ds

public text v1 · immutable
·published 2007-10-11 03:44 UTC
rendered paste body
        //a = player 1 x1,y1  b = player 2 x2,y2
        public static bool Intersects(Texture2D a, Texture2D b)
        {
         //   if (Collision.Intersects(a.bounds, b.bounds))
            {
                uint[] bitsA = new uint[a.Width * a.Height];
                a.GetData<uint>(bitsA);

                uint[] bitsB = new uint[b.Width * b.Height];
                b.GetData<uint>(bitsB);

                //later change this to player.Texture2D
                //                     player.x , y ..  player2.x, y
                int x1d = Math.Max(x, x2);
                int x2d = Math.Min(x + a.Width, x2 + b.Width);

                int y1d = Math.Max(y, y2);
                int y2d = Math.Min(y + a.Height, y2 + b.Height);



                for (int yd = y1d; y < y2d; ++y)
                {
                    for (int xd = x1d; x < x2d; ++x)
                    {
                        if (((bitsA[(xd - x) + (yd - y) * a.Width] & 0xFF000000) >> 24) > 20 &&
                            ((bitsB[(xd - x2) + (yd - y2) * b.Width] & 0xFF000000) >> 24) > 20)
                            return true;
                    }
                }
            }
            return false;
        }

-- when running I get a "An unhandled exception of type 'System.IndexOutOfRangeException'

on:
        if (((bitsA[(xd - x) + (yd - y) * a.Width] & 0xFF000000) >> 24) > 20 &&
                            ((bitsB[(xd - x2) + (yd - y2) * b.Width] & 0xFF000000) >> 24) > 20)
                            return true;

--