Mario: Fix bug of being teleported after landing from jump

In rare cases Mario was teleported when landing from a high jump as a
visitor could've been fired in the wrong moment (before Mario's Y was
reset to be standing on the ground) and left/right detect would trigger
and teleport mario 1 block away
This commit is contained in:
zvon 2021-05-27 16:57:21 +02:00
parent b8c56c06fd
commit 757a03568d

View File

@ -86,7 +86,8 @@ void Mario::handleVisitor(MarioVisitor &visitor) {
// TODO more readable function names
if ( visitor.isStopped() ) {
setPos( visitor.getStopX(), getPos().getY());
} else if ( visitor.canGoLeft() != visitor.canGoRight() ) {
} else if ( visitor.canGoLeft() != visitor.canGoRight() && !(on_ground && visitor.getMovementBlockage().getY() > getPos().getY() + BLOCK_SIZE/2) ) {
// only stop mario on ground if the block obstructs at least half of him (important for bug when mario lands from a high jump and is teleported if visitor is fired at wrong moment)
SDLPP::Vec2D<double> next_pos = { visitor.getMovementBlockage().getX() + (visitor.canGoLeft() * -1 + visitor.canGoRight() * 1) * BLOCK_SIZE, getPos().getY() };
setPos(next_pos);
} else if (visitor.moveTop() && jumping && !stop_jump) {