... and the other side
After the existing code:
if (px > 40) {
dpx = -dpx;
}
insert some similar code:
if (px < -40) {
dpx = -dpx;
}
Both of the above two sections of code together
can be replaced by the single following section:
if ((px < -40) || (px > 40)) {
dpx = -dpx;
}
Although compact, this code is more difficult to read.
The || notation represents the logical OR.
Note also the need for an extra set of parentheses.