From 757a03568d8667f6bf57e7d13a86f7d3a909d949 Mon Sep 17 00:00:00 2001 From: zvon Date: Thu, 27 May 2021 16:57:21 +0200 Subject: [PATCH] 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 --- mario/mario.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mario/mario.cpp b/mario/mario.cpp index bd7bbe5..fc9fe7a 100644 --- a/mario/mario.cpp +++ b/mario/mario.cpp @@ -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 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) {