(here is a really, really great site on collision detection, someone once posted:
http://jeffreythompson.org/collision-detection/matrix-transformations.php)
-
one thing I notice with your sketch is that you have a chance for infinite recursion since you call check(x,y,w) inside itself. the good thing for now is, that the collision detection doesn’t work, but if it did it could become an issue, your code infinitely repeating when it doesn’t detect a free place for a new object…
-
you are basically checking if a POINT is inside a rectangle.
but you need to check if any part of a rectangle is within another rectangle.
so it is possible that they can overlap, because the upper left corner of one rectangle can be outside another, but they still overlap.
if (cX >= pos.x && cX <= pos.x+wd && cY >= pos.y && cY <= pos.y+wd)
is cX in between pos.x and pos.x + wd = is the point inside, not the width
- its always your fault.
the code does what you tell it :-)))))