O'Reilly logo

Raspberry Pi Cookbook for Python Programmers by Tim Cox

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a bat and ball game

A classic bat and ball game can be created using the drawing tools of canvas and by detecting the collisions of the objects. The user will be able to control the green paddle using the left and right cursor keys to aim the ball at the bricks and hit them until they have all been destroyed.

Creating a bat and ball game

Control the bat to aim the ball at the bricks

Getting ready

This example requires a screen and keyboard attached to the Raspberry Pi or X11 Forwarding and X server.

How to do it…

Create the following script, bouncingball.py:

#!/usr/bin/python3 # bouncingball.py import tkinter as TK import time VERT,HOREZ=0,1 xTOP,yTOP = 0,1 xBTM,yBTM = 2,3 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required