CollisionDirection CollisionHandler::DetectCollisionWithObj(MovingObject& _obj, DisplayableObject& _ref) { if (_obj.GetID() == _ref.GetID()) return NO_COL; return DetectCollisionWithRect(_obj.GetCoordinates(), _ref.GetCoordinates()); }
void CollisionHandler::ReactToCollision(DisplayableObject& _obj, sf::FloatRect _refRect, CollisionDirection _direction) { sf::FloatRect objRect = _obj.GetCoordinates(); switch (_direction) { case TOP: objRect.top -= (objRect.top + objRect.height - _refRect.top); break; case BOTTOM: objRect.top += (_refRect.top + _refRect.height - objRect.top); break; case LEFT: objRect.left -= (objRect.left + objRect.width - _refRect.left); break; case RIGHT: objRect.left += (_refRect.left + _refRect.width - objRect.left); break; case NO_COL: default: break; } m_gameEngine->UpdateForegroundItem(_obj.GetID(), objRect); }