Page 87 - Programming the Raspberry Pi Getting Started with Python
P. 87
The raspberry_x and raspberry_y variables just become variables of the new Raspberry class.
Also, when an instance of a raspberry is created, its x position will be set randomly. The old
update_raspberry function has now become a method on Raspberry called just update. Similarly,
the check_for_catch function now asks the raspberry if it has been caught.
Having defined a raspberry class, we create an instance of it like this:
Thus, when we want to check for a catch, the check_for_catch just asks the raspberry like this:
The call to display the score has also been moved out of the check_for_catch function and into the
main loop. With everything now working just as it did before, it is time to add more raspberries. The
final version of the game can be found in the file 08_06_rasp_game_final.py. It is listed here in full: