Let’s start by adding a background to the game scene. This can be done with a couple more screen.blit() calls.
At the end of section #3, after loading the player image, add the following code:
sky = pygame.image.load("resources/images/sky.png")
spacestation = pygame.image.load("resources/images/spacestation.png")This loads the images and puts them into specific variables. Now they have to be drawn on screen. But if you check the grass image, you will notice that it won’t cover the entire screen area, which is 1550 x 1000. This means you have to tile the sky over the screen area to cover it completely.
Add the following code to game.py at the beginning of section #6 (before the player is drawn on screen):
for x in range(width//sky.get_width()+1):
for y in range(height//sky.get_height()+1):
screen.blit(sky,(x*100,y*100))
screen.blit(spacestation, (0, 60))
screen.blit(spacestation, (0, 180))
screen.blit(spacestation, (0, 310))
screen.blit(spacestation, (0, 435))As you can see, the for statement loops through x first. Then, within that for loop, it loops through y and draws the sky at the x and y values generated by the for loops. Then we add the spacestations.