The same drifting ship โ but the trigonometry is Python
โ Back to Fun TimeThere 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/asteroids_rules.py | The rules: angles, drifting, wrapping, breaking | point_from, wrap_position, thrust_ship, hit_rocks |
| pylib/asteroids_draw.py | Painting space โ Python calling the canvas | draw_ship, draw_rock, render_game |
| pylib/asteroids_web.py | The glue: the held keys, the taps, the loop | do_action, on_key_down, frame |
๐ Compare the two versions. Open lib/asteroids-rules.js and pylib/asteroids_rules.py side by side โ same ideas, two languages.
๐ ๏ธ Build it yourself: Build Asteroids 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.