Exemplo n.º 1
0
        public override bool Collide(CircleMask mask, float dx = 0, float dy = 0)
        {
            Rectangle range = mask.Bounds;
            range.Offset((int)(-AbsoluteLeft - dx), (int)(-AbsoluteTop - dy));

            int xStart = (int)(range.X / CellWidth);
            int yStart = (int)(range.Y / CellHeight);
            int xEnd = (int)((range.X + range.Width - 1) / CellWidth);
            int yEnd = (int)((range.Y + range.Height - 1) / CellHeight);

            Rectangle box = new Rectangle(0, 0, (int)CellWidth, (int)CellHeight);
            Vector2 shiftedPosition;

            for(int x = xStart; x <= xEnd; ++x)
                for (int y = yStart; y <= yEnd; ++y)
                {
                    if (this[x, y])
                    {
                        box.X = (int)(x * CellWidth + AbsoluteLeft + dx);
                        box.Y = (int)(y * CellHeight + AbsoluteTop + dy);
                        shiftedPosition = box.Closest(mask.AbsolutePosition);
                        if (shiftedPosition.LengthSquared(mask.AbsolutePosition) <= (mask.Radius * mask.Radius))
                            return true;
                    }
                }

            return false;
        }