๐Ÿ‘พ SPACE INVADERS in Python

The same fleet โ€” but every alien is marched by Python

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

โŒจ๏ธ Controls

  • โ† โ†’ or A D slide the ship
  • SPACE, โ†‘ or W fire
  • Tapping the field fires too
  • P pause  โ€ข  R 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

  • Shoot all 24 aliens before they land on you.
  • Only one of your bullets can be in the air at a time โ€” make it count.
  • The hollow shots are alien bombs. Do not stand under them.
  • Every time the fleet touches a wall it drops a row closer.

๐Ÿ† Scoring

  • The back row is worth 40, the front row 10.
  • Clearing a whole wave is another 100.
  • The fewer aliens are left, the faster they march.
  • Tip: shoot a column out at one end and the fleet gets extra room to march โ€” that buys you time.

๐Ÿง‘โ€๐Ÿ’ป 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/invaders_rules.py The rules: the fleet, the shots, the hits alien_rect, move_fleet, fire_bullet, hit_aliens
pylib/invaders_draw.py Painting the fleet โ€” Python calling the canvas draw_alien, draw_ship, render_game
pylib/invaders_web.py The glue: the keyboard, the taps, the loop do_action, on_key_down, frame

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

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