๐Ÿค FLAPPY in Python

The same bird โ€” but the gravity is written in Python

โ† Back to Fun Time
๐Ÿ Starting Pythonโ€ฆ
Score
0
Level
1
Pipes
1
Best
0

โŒจ๏ธ Controls

  • SPACE, โ†‘ or W flap
  • Clicking or tapping the sky flaps too
  • P pause  โ€ข  R new game
  • Your first flap starts the game โ€” no need to press start.
  • ๐ŸŽฎ 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

  • The bird falls all by itself. Flapping is the only thing you control.
  • Fly through the gap in each pipe.
  • Touching a pipe, the ground or the ceiling ends the run.
  • Short taps beat long ones โ€” flap little and often.

๐Ÿ† Scoring

  • One point per pipe you get through.
  • Every 5 pipes the game speeds up a little, all the way to level 15.
  • Ten pipes is a good run. Twenty is showing off.
  • Tip: aim for the middle of the gap, not the bottom of it.

๐Ÿง‘โ€๐Ÿ’ป 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/flappy_rules.py The rules: gravity, pipes, crashes apply_gravity, flap, move_pipes, is_crashed
pylib/flappy_draw.py Painting the sky โ€” Python calling the canvas draw_pipe, draw_bird, render_game
pylib/flappy_web.py The glue: the keyboard, the taps, the loop do_action, on_board_press, frame

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

๐Ÿ› ๏ธ Build it yourself: Build Flappy 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.