๐Ÿงฑ BREAKOUT in Python

The same bouncing ball โ€” but every line of the physics is Python

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Score
0
Lives
3
Bricks
35
Best
0

โŒจ๏ธ Controls

  • โ† โ†’ or A D slide the paddle
  • The paddle also follows your mouse or finger across the field
  • SPACE launch the ball  โ€ข  P pause
  • R start a new game
  • ๐ŸŽฎ Xbox controller? Just plug it in or pair it โ€” the stick and D-pad are the arrow keys, A is SPACE, Menu pauses and View starts again

๐ŸŽฏ How to play

  • Keep the ball off the floor. You get three lives.
  • Every brick the ball touches disappears.
  • Clear all 35 bricks to win.
  • Where the ball lands on the paddle decides where it goes next โ€” that is your steering.

๐Ÿ† Scoring

  • The top row is worth 50 points, the bottom row 10.
  • A perfect wall is 1050 points.
  • Hit the ball with the edge of the paddle to send it sideways at the corners.
  • The middle of the paddle sends it straight up โ€” safe, but slow going.

๐Ÿง‘โ€๐Ÿ’ป This whole game is Python

There is almost no JavaScript on this page. The browser downloaded Pyodide โ€” a complete Python interpreter compiled to WebAssembly โ€” and then ran the .py files in funtime/pylib/. Python does the rules, the maths and the drawing.

File What it does Good functions to try re-writing
pylib/breakout_rules.py The rules: the ball, the bounces, the bricks hits_rect, bounce_off_walls, bounce_off_paddle, break_bricks
pylib/breakout_draw.py Painting the wall โ€” Python calling the canvas draw_brick, draw_paddle, render_game
pylib/breakout_web.py The glue: the keyboard, the mouse, the loop do_action, on_mouse_move, frame

๐Ÿ” Compare the two versions. Open lib/breakout-rules.js and pylib/breakout_rules.py side by side โ€” same ideas, two languages.

๐Ÿ› ๏ธ Build it yourself: Build Breakout in Python walks you through the functions one at a time.

โš ๏ธ If the game never starts: the page has to read its .py files, which a browser will not do for a page opened straight off your disk. Use the live site, or run python3 -m http.server in the project folder.