ThatSnail

Untitled

Oct 26th, 2012
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. bool Obj::isCollidingAt(double x, double y, ObjectType type)
  2. {
  3.     return getCollisionAt(x, y, type) != NULL;
  4. }
  5.  
  6. Obj* Obj::getCollisionAt(double x, double y, ObjectType type)
  7. {
  8.     for(unsigned int i=0; i<HGame::getObjectList().size(); i++)
  9.     {
  10.         Obj* o = HGame::getObjectList().at(i);
  11.         if(o->objectType == type)
  12.         {
  13.             Spr* spr1 = sprite;
  14.             Spr* spr2 = o->sprite;
  15.  
  16.             sf::Rect<double> rect1 = spr1->getTransformedHitbox(x, y);
  17.             sf::Rect<double> rect2 = spr2->getTransformedHitbox(o->x, o->y);
  18.  
  19.             sf::Rect<double> overlap;
  20.             if(rect1.Intersects(rect2, &overlap))
  21.             {
  22.                 for(int sx = overlap.Left; sx < overlap.Right; sx++)
  23.                 {
  24.                     for(int sy = overlap.Top; sy < overlap.Bottom; sy++)
  25.                     {
  26.                         if(isObjectAtPoint(sx, sy) && o->isObjectAtPoint(sx, sy))
  27.                         {
  28.                             return o;
  29.                         }
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.     }
  35.     return NULL;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment