psiko_scweek
October 1st, 2006, 06:12
Hey!! whats wrong with my collision detection code? It works great, cept it registers the collision one pixel too many! so, basically it registers one pixel outside of my image.
nt obj_IsCollision(Object *object1, Object *object2)
{
int obj_top1, obj_top2;
int obj_bot1, obj_bot2;
int obj_rigt1, obj_rigt2;
int obj_left1, obj_left2;
obj_left1 = object1->getX();
obj_left2 = object2->getX();
obj_top1 = object1->getY();
obj_top2 = object2->getY();
obj_rigt1 = object1->getX() + object1->getGraphicWidth();
obj_rigt2 = object2->getX() + object2->getGraphicWidth();
obj_bot1 = object1->getY() + object1->getGraphicHeight();
obj_bot2 = object2->getY() + object2->getGraphicHeight();
if (obj_bot1 < obj_top2) return(0);
if (obj_top1 > obj_bot2) return(0);
if (obj_rigt1 < obj_left2) return(0);
if (obj_left1 > obj_rigt2) return(0);
return 1;
nt obj_IsCollision(Object *object1, Object *object2)
{
int obj_top1, obj_top2;
int obj_bot1, obj_bot2;
int obj_rigt1, obj_rigt2;
int obj_left1, obj_left2;
obj_left1 = object1->getX();
obj_left2 = object2->getX();
obj_top1 = object1->getY();
obj_top2 = object2->getY();
obj_rigt1 = object1->getX() + object1->getGraphicWidth();
obj_rigt2 = object2->getX() + object2->getGraphicWidth();
obj_bot1 = object1->getY() + object1->getGraphicHeight();
obj_bot2 = object2->getY() + object2->getGraphicHeight();
if (obj_bot1 < obj_top2) return(0);
if (obj_top1 > obj_bot2) return(0);
if (obj_rigt1 < obj_left2) return(0);
if (obj_left1 > obj_rigt2) return(0);
return 1;