Module 6 - Section 0 - Repeat!

6.0.2 - Bounce



To bounce the object at the edges of the screen we change the direction of the object's speed when it reaches the edges.

if rect_x >= 650 or rect_x <= 0: speed_x *= -1 if rect_y >= 450 or rect_y <= 0: speed_y *= -1

If the object is larger or smaller or if it is different (circle) we have to change the borders in the previous commands accordingly.