Game Development Reference
In-Depth Information
Figure 18-3: Example of coordinates inside and outside
of a rectangle. The (50, 30), (85, 30) and (50, 50) points
are inside the rectangle, and all the others are outside.
18. else:
19. return False
If just one of the four expressions in the condition on line 16 is False , then we should
have isPointInsideRect() return the value False .
This function will be called from the doRectsOverlap() function to see if any of the
corners in the two pygame.Rect objects are inside each other. These two functions give
us the power to do collision detection between two rectangles.
The pygame.time.Clock Object and tick()
Method
Much of lines 22 to 43 do the same thing that Animation program in the last chapter did:
initialize the Pygame library, set WINDOWHEIGHT and WINDOWWIDTH , and put together
the color and direction constants. However, line 24 is new:
24. mainClock = pygame.time.Clock()
In the previous Animation program, we had a call to time.sleep(0.02) inside the
game loop in order to slow down the program enough so that we could see the blocks
moving. The problem with this is that the program might run too fast on fast computers and
too slow on slow computers. We want to limit the maximum number of iterations through
the game loop there are per second.
Search WWH ::




Custom Search