Rectangle Collision Detection source code

This snippet submitted by David Nielsen on 2005-05-30. It has been viewed 29976 times.
Rating of 6.1 with 171 votes

#define LEFT	0
#define TOP	1
#define RIGHT	2
#define BOTTOM	3

bool collideRectRect(int rect1[4], int rect2[4])
{
	if(rect1[RIGHT] < rect2[LEFT] ||
	   rect1[LEFT] > rect2[RIGHT] ||
	   rect1[TOP] < rect2[BOTTOM] ||
	   rect1[BOTTOM] > rect2[TOP]){
	   	return false;
	}else{
		return true;
	}
}
 
 




More C and C++ source code snippets

Add a snippet!