Game Development Reference
In-Depth Information
17 - Graphics and Animation
Figure 17-6: The Animation program.
How the Animation Program Works
In this program, we will have three different colored blocks moving around and
bouncing off the walls. In order to do this, we need to first consider exactly how we want
the blocks to move.
Moving and Bouncing the Blocks
Each block will move in one of four diagonal directions: down and left, down and right,
up and left, or up and right. When the block hits the side of the window, we want it to
"bounce" off the wall and move in a new diagonal direction. The blocks will bounce as
shown in this picture:
The new direction that a block moves after it bounces depends on two things: which
direction it was moving before the bounce and which wall it bounced off of. There are a
total of eight possible ways a block can bounce: two different ways for each of the four
walls. For example, if a block is moving down and right, and then bounces off of the
bottom edge of the window, we want the block's new direction to be up and right.
We can represent the blocks with a Rect object to represent the position and size of the
block, a tuple of three ints to represent the color of the block, and an integer to represent 327
Search WWH ::




Custom Search