From 1ffb723f96100eff4ca9eade1406aadef47842f1 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Mon, 24 Mar 2025 14:15:19 +0100 Subject: [PATCH] Handle horizontal boundaries on platform --- src/platform.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platform.cpp b/src/platform.cpp index 2aa95de..287fa4e 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -23,15 +23,22 @@ void Platform::draw(QPainter& painter) { } void Platform::timerEvent(QTimerEvent*) { - m_parent->update(); - int direction = 0; if (m_parent->leftArrowPressed && !m_parent->rightArrowPressed) direction = -1; else if (m_parent->rightArrowPressed && !m_parent->leftArrowPressed) direction = 1; + // Don't move on horizontal collision + QRect rct = m_parent->rect(); + if (m_x > rct.width() - PLATFORM_WIDTH && direction == 1) + direction = 0; + if (m_x < 0 && direction == -1) + direction = 0; + m_x += direction * SPEED; + + m_parent->update(); } QRect Platform::rect() const {