Part 10 - Controllers and Graphics

This section will introduce a method to animate your graphics. You can use this technique to animate custom graphics from a function, or using the pre-made graphics from the PyGame library.

You will also be shown how to control graphical movement by either getting the coordinates of the mouse pointer or reading key presses from the keyboard.

What to do/hand in?

1. Read and work through "Part 10 - Controllers and Graphics". Make sure that you experiment with both keyboard and mouse input.

2. Complete the lab in Part E. Use functions to create your two graphics.

Submit:

1. Python file with your two moving graphic objects.

Part 10--Controllers and Graphics.pdf

Hints and FAQ's

1. For the bonus part, only worry about keeping the graphic controlled by the keyboard in the window. It is okay if the mouse controlled graphic goes out of the window.

2. Use an if statement(s) to verify that the x_coord, and y_coord variables are both greater than zero. This will keep your graphic from going off the left and top of the window. Reset the x and y coordinates to zero if you detect that they are negative values. To keep your graphic from going off the right and bottom there is a little bit more involved. You know the width and height of your window. You will also need to know the width and height of your graphic.