Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Obj::isCollidingAt(double x, double y, ObjectType type)
- {
- return getCollisionAt(x, y, type) != NULL;
- }
- Obj* Obj::getCollisionAt(double x, double y, ObjectType type)
- {
- for(unsigned int i=0; i<HGame::getObjectList().size(); i++)
- {
- Obj* o = HGame::getObjectList().at(i);
- if(o->objectType == type)
- {
- Spr* spr1 = sprite;
- Spr* spr2 = o->sprite;
- sf::Rect<double> rect1 = spr1->getTransformedHitbox(x, y);
- sf::Rect<double> rect2 = spr2->getTransformedHitbox(o->x, o->y);
- sf::Rect<double> overlap;
- if(rect1.Intersects(rect2, &overlap))
- {
- for(int sx = overlap.Left; sx < overlap.Right; sx++)
- {
- for(int sy = overlap.Top; sy < overlap.Bottom; sy++)
- {
- if(isObjectAtPoint(sx, sy) && o->isObjectAtPoint(sx, sy))
- {
- return o;
- }
- }
- }
- }
- }
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment