Module 5 - Section 1 - Graphics
Module 5 - Section 1 - Graphics
- describe how to draw shapes
- create code to animate a shape
- create code to bounce a shape inside a windows
- reproduce the code to animate and bounce two objects
- organize the code for multiple animation
5.1.3 - Multiple objects
Things are starting to get very interesting. If we wanted to have another RED rectangle inside our graphics screen what should we do?
Let's review the steps again.
Draw the rectangle in the position that we want (ex. 250, 180), with the size that we want (ex. 80,80) and if we want just the frame, use another parameter for the thickness (ex. 3)
pygame.draw.rect(screen, RED, [250, 180, 80, 80], 3)
Copy the command after the moving white rectangle drawing command.
If you haven't managed to write the correct code you can download it from here
Which of the two shapes is in the front? Why? Can you change the code so the other shape is in the front.
Also remember that you can change the game speed in line 66 in command
clock.tick(60)
Greater numbers result in greater speed but sometimes the computers graphics system cannot keep up. Change the number to see the difference but do not go over 120.
Also changing the speed of the rectangle in lines 31 and 32 result in smoother movement when we reduce the numbers. Try using speeds 1 to 10.
speed_x = 2 # X speed of rectangle
speed_y = 2 # Y speed of rectangle