-
Collision Detection
Ze engine... She's alive! :D
Well everything thus far is just dandy, but there's something I'll need to consider later on - collision detection.
Can someone explain to me algorithmically how this is best done at it's simplest - I.E. in a 2D engine?
-
You using vectors or sprites?
For sprites the simplest method is bounding box collision detection. You have a box for the width and height of an object and then you go through every object checking to see if it overlaps with the one you're testing
Code:
bool overlap(Rectangle box, Rectangle test)
{
if (box.x + box.w > test.x && box.x < test.x + test.w && box.y + box.h > test.y && box.y < test.y + test.h)
return true;
else
return false;
}
If you get an overlap go through every pixel of box sprite and if a pixel of box sprite is in the same position as a pixel of test sprite you have a collision.
-
Sprites.
Cheers that helped a lot :)