Advertisement
NovaYoshi

collision detection in FHBG SDL

Apr 4th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. int __pure__ ChkCollision (Object *Obj1, Object *Obj2) {
  2.   int LeftA, RightA, TopA, BottomA;
  3.   int LeftB, RightB, TopB, BottomB;
  4.  
  5.   LeftA = Obj1->PosX>>8;
  6.   RightA = LeftA+Obj1->Width-1;
  7.   TopA = Obj1->PosY>>8;
  8.   BottomA = TopA+Obj1->Height-1;
  9.  
  10.   LeftB = Obj2->PosX>>8;
  11.   RightB = LeftB+Obj2->Width-1;
  12.   TopB = Obj2->PosY>>8;
  13.   BottomB = TopB+Obj2->Width-1;
  14.  
  15.   if(LeftA >= LeftB
  16.   && LeftA <= RightB
  17.   && TopA >= TopB
  18.   && TopA <= BottomB)
  19.     return 1;
  20.   if(LeftB >= LeftA
  21.   && LeftB <= RightA
  22.   && TopB >= TopA
  23.   && TopB <= BottomA)
  24.     return 1;
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement