C++ (Qt)
void MyItem::keyPressEvent(QKeyEvent *event)
{
auto key = event->key();
if (key == Qt::Key_Up && speed<maxSpeed)
if (speed < 0) speed += dec;
else speed += acc;
if (key == Qt::Key_Down && speed>-maxSpeed)
if (speed > 0) speed -= dec;
else speed -= acc;
if (key != Qt::Key_Up && key != Qt::Key_Down)
if (speed - dec > 0) speed -= dec;
else if (speed + dec < 0) speed += dec;
else speed = 0;
if (key == Qt::Key_Right && speed!=0) angle += turnSpeed * speed/maxSpeed;
if (key == Qt::Key_Left && speed!=0) angle -= turnSpeed * speed/maxSpeed;
car[0].speed = speed;
car[0].angle = angle;
}