Source code for the sample is here: src
Create a directory p12, download all files into this directory, then
run the program cat.py in IDLE3 or with "python3 cat.py .
This game uses keyboard presses for action, the four arrow keys. You can play it: move the cat with arrow keys to capture the mouse, and see what happens. The cat captures the mouse, and the mouse collects cheese.
Arrow keys move the cat, and the cat's (x,y) coordinates are then compared to the mouse's (x,y) coordinates, then action is taken depending on how far the cat and mouse are from eachother. The mouse's motion is somewhat random, but also depends on the position of the cat.
Things you can do
1. Change images. These must be GIF images ending with .gif 2. Change sounds. These must be WAV files ending in .wav Here is a website for sounds: http://www.wavsource.com/sfx/sfx.htm 3. Change logic for mouse movement. Note that the mouse makes random moves picking a number by: run = choice([-16,-12,-8,-4,-2,2,4,8,12,16]) rise = choice([-16,-12,-8,-4,-2,2,4,8,12,16]) Then, the rise(x) and run(y) are restricted so that the mouse stays on the 400x400 board Changing these numbers affects how the mouse moves. 4. Change cat speed. The cat moves 6 units up, down, left, or right on each arrow press. 5. Do something with the cat and mouse score. Nothing is done now except show cat_score and mouse_score. You could play a tune then restart the game when one of them reaches a value, say 5. 6. You could move cheeses around. These are hardcoded now at certain positions which are each checked. 7. Change the board background and/or size. If the board size is changed then hardcoded positions would also need to be changed.
With some changes on mouse response, it can be made much easier for the cat, or impossible for the cat.
The mouse could move without cat move key presses, a different method, yet this keyboard trigger for movement is enough for certain kinds of interesting responsive games.