|
58 | 58 | pygame.quit()
|
59 | 59 | sys.exit()
|
60 | 60 |
|
61 |
| -# clear the surface by filling with black |
| 61 | + # clear the surface by filling with black |
62 | 62 | windowSurface.fill(BLACK)
|
63 | 63 |
|
64 |
| -# check if the first rectangle is off screen? If it is, |
65 |
| -# change the direction it moves in |
| 64 | + # check if the first rectangle is off screen? If it is, |
| 65 | + # change the direction it moves in |
66 | 66 | if (rectangle.right > WINDOWWIDTH):
|
67 | 67 | move = - move
|
68 | 68 | elif (rectangle.left <= 0):
|
69 | 69 | move = -move
|
70 | 70 |
|
71 |
| -# check if rectangle2 is off screen? If it is, change the direction it |
72 |
| -# moves in |
| 71 | + # check if rectangle2 is off screen? If it is, change the direction it |
| 72 | + # moves in |
73 | 73 |
|
74 | 74 | if (rectangle2.right > WINDOWWIDTH):
|
75 | 75 | move2 = - move2
|
76 | 76 | elif (rectangle2.left <= 0):
|
77 | 77 | move2 = -move2
|
78 | 78 |
|
79 |
| -# do rectangle and rectangle2 overlap? If they do, change the direction they |
80 |
| -# move in |
| 79 | + # do rectangle and rectangle2 overlap? If they do, change the direction they |
| 80 | + # move in |
81 | 81 | if ((rectangle2.left > rectangle.left) and (rectangle2.left < rectangle.right )) or ((rectangle2.right > rectangle.left) and (rectangle2.right < rectangle.right)):
|
82 | 82 | move = -move
|
83 | 83 | move2 = -move2
|
84 | 84 |
|
85 |
| -# alter position of the rectangles - i.e. make them move |
| 85 | + # alter position of the rectangles - i.e. make them move |
86 | 86 | topx = rectangle.left + move
|
87 | 87 | topx2 = rectangle2.left + move2
|
88 | 88 |
|
89 |
| -# redraw rectangles |
| 89 | + # redraw rectangles |
90 | 90 | rectangle = pygame.draw.rect(windowSurface, RED, (topx, 50, 100, 50))
|
91 | 91 | rectangle2 = pygame.draw.rect(windowSurface, GREEN, (topx2, 50, 50, 50))
|
92 | 92 |
|
|
0 commit comments