I'm trying to make a loop where it returns whether or not a rectangle collides and then to which coords the rectangle should move to.
I'm calling my function like this:
rectangles2[i].rect = rectangleupdated(i, rectangles2);
And this is inside my function:
private Rectangle rectangleupdated(int i, List<rectList> rectangles2)
{
//fills rectangles with rectangles to check intersect with
BOTTOM = rectangles2[i].rect;
BOTTOM_LEFT = rectangles2[i].rect;
BOTTOM_RIGHT = rectangles2[i].rect;
//bool to be set to false if intersects returns true
bBOTTOM = true;
bBOTTOM_LEFT = true;
bBOTTOM_RIGHT = true;
//move the intersect rectangles
BOTTOM.Y++;
BOTTOM_LEFT.Y++;
BOTTOM_LEFT.X--;
BOTTOM_RIGHT.Y++;
BOTTOM_RIGHT.X++;
foreach (rectList rects in rectangles2)
{
if (!rects.type.Contains("bg"))
{
if (rectangles2[i].rect.Y < 500)
{
if (BOTTOM.IntersectsWith(rects.rect))
{
bBOTTOM = false;
}
else if (BOTTOM_LEFT.IntersectsWith(rects.rect))
{
bBOTTOM_LEFT = false;
}
else if (BOTTOM_RIGHT.IntersectsWith(rects.rect))
{
bBOTTOM_RIGHT = false;
}
}
else
{
return rectangles2[i].rect;
}
}
}
if (bBOTTOM == true) return BOTTOM;
else if (bBOTTOM_RIGHT == true) return BOTTOM_RIGHT;
else if (bBOTTOM_LEFT == true) return BOTTOM_LEFT;
return rectangles2[i].rect;
}
I think I know a little bit why it's lagging so hard but I don't know how to fix it / make this code more usable.