Drawing with Pygame
Drawing on the screen has two stages. The first is that you draw onto the canvas (or surface object), and the second is that you update the screen with those changes. To make the window background white, use
In our game, we’re going to use two shapes. The first is a rectangle. To draw a rectangle, you need to specify the surface object you are drawing on, which will be our canvas
gameSurface; the color; the X coordinate of the rectangle’s top-left corner; the Y coordinate of the rectangle’s top-left corner; and its width and height. The coordinates are measured from the top-left corner of the window, so X values get higher as you cross the screen from left to right, and Y values get higher as you go down the screen.
The command to draw a rectangle looks like this:
Imagine you wanted to draw a green rectangle that was 150 pixels wide by 75 pixels high, and you wanted to put it at the coordinate X=30, Y=90. Here’s how you’d do that:
The frame around our game arena (see Figure 13-1 ...