Handle horizontal boundaries on platform

This commit is contained in:
ItsDrike 2025-03-24 14:15:19 +01:00
parent adaa571b28
commit 1ffb723f96
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -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 {