SDLPP: if one object is entirely contained within another, it is a collision

This commit is contained in:
zvon 2021-04-29 19:48:45 +02:00
parent 4f20274f11
commit 4e81ac6562

View File

@ -72,6 +72,16 @@ bool intersects( const SDLPP::CollisionPolygon &p1,
if ( p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() || if ( p1.rightmost() < p2.leftmost() || p2.rightmost() < p1.leftmost() ||
p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost() ) p1.bottommost() < p2.topmost() || p2.bottommost() < p1.topmost() )
return false; return false;
if ( p1.leftmost() < p2.leftmost() && p1.topmost() < p2.topmost() &&
p1.rightmost() > p2.rightmost() &&
p1.bottommost() > p2.bottommost() ) {
return true;
}
if ( p2.leftmost() < p1.leftmost() && p2.topmost() < p1.topmost() &&
p2.rightmost() > p1.rightmost() &&
p2.bottommost() > p1.bottommost() ) {
return true;
}
for ( auto &line : p1.getLines() ) { for ( auto &line : p1.getLines() ) {
for ( auto &line2 : p2.getLines() ) { for ( auto &line2 : p2.getLines() ) {
if ( linesCross( line, line2 ) ) if ( linesCross( line, line2 ) )