Something to ponder, if rectangleY
starts at 0, then is rectangleY < 50
always true by the next frame? If we try doing a manual trace of lines 25 and 26 for a few frames…
0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction
0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction
0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction
This shows us a useful pattern for identifying the problem. Which is that rectangleY would never reach a value that is greater than 50 but less than 718 with both it’s initial value and the amount of movement given from rectangleDirection
The simplest solution would be to changle rectangleY
's initial value to something greater than 50. But you could also adjust rectangleDirection
to a value greater than 50 (it wouldn’t look good, though).