Handle horizontal boundaries on platform
This commit is contained in:
parent
adaa571b28
commit
1ffb723f96
1 changed files with 9 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue