Drawing the Bricks
Now we have a map, and we know how to make rectangles, we can draw the start screen showing the brickwork raspberry.
Our game map is 20 rows of 20 columns, and each position on the map can have a brick in it, have nothing in it, or have the ball or half of the bat in it (because the bat occupies two spaces).
To draw a brick on screen, we need to take a brick’s position on the map and use it to calculate the brick’s position on screen. Each position on the map is a square with sides of 20 pixels, so a brick’s real coordinate on the screen (in pixels) is 20 times its coordinate in the game (measured in our map rows and columns). For example, the brick that’s in the fifth row and the fourth column of our map is 100 pixels from the left of the window edge, and 80 pixels from the top. To calculate these pixel positions for Pygame, we’re going to create two functions called
The next step is to create a function to draw a brick. In the last chapter, you learned how to pass arguments to a function. In this chapter, we extend the idea and pass several values at once. Our function
drawbrick() receives the X map coordinate, Y map coordinate, and the color value ...