Hardware Reference
In-Depth Information
you want it to inish, along with the line thickness. here are two ways of detecting if these
overlap: he irst is to look at what is already drawn on the screen to see if anything is in the
place you are going to draw the next block. he second, and the one you shall use here, is to
compute the extent of the objects and see if there is an overlap. Figure 5-4 shows this calcula-
tion for a rectangle and a line. Note the diference in how the line thickness is handled. For a
line the thickness is built up by drawing in pixels either side of the required line, whereas for
a rectangle the thickness is built up by drawing in pixels inside the rectangle. his is the way
that Pygame handles the graphic coordinates; other systems such as Apple's QuickTime take
a diferent approach, with the deined line being in between the pixels and any line thickness
being below and to the right of the line. here are many ways to implement graphics drawing
routines.
Figure 5-4:
Calculating
limits for a
collision.
You will see from Figure 5-4 that the limits set depend on the direction of approach the
object has, so when going from left to right it is diferent than going from right to left.
The Test Bounce
Armed with this information, you can now get some coding done and set the framework for
your game. Type in the code in Listing 5-1, and it will bounce a square around a window at
high speed.
Search WWH ::




Custom Search