Visualizations
254 / 500

254 · Games

Asteroids

The arcade classic with glowing vector lines and an AI pilot.

A full game in the style of the 1979 vector arcade machine: a ship with inertia, wrap-around space, asteroids that split when shot, flying saucers that shoot back, hyperspace and score. Every line is stroked three times with additive blending onto a screen that only partly fades between frames, imitating a glowing phosphor tube, and explosions throw out shards. Until you take over, an AI pilot leads its shots at the most dangerous target and dodges what is coming, with the occasional fatal lapse.

Try it. Click the view, then use the arrow keys to fly, space to shoot and down for hyperspace. On a touch screen, hold to steer toward your finger and fire. Leave it alone and the AI plays.

  • Vector graphics
  • Phosphor persistence and bloom
  • Game AI

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a playable Asteroids game in the style of the 1979 vector arcade machine with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and resizes with the window. Paint it black.
- Draw everything as thin white outlines, never filled shapes: the ship is a five-point arrowhead, and each asteroid is a jagged polygon made by placing 8 to 11 points around a circle at random radii.
- Give the ship inertia: the left and right arrows rotate it, up thrusts along its heading, and a little drag slows it down. Space fires bullets that inherit the ship's velocity and expire after about a second.
- Space wraps around: anything leaving one edge comes back on the opposite one. When an object straddles an edge, draw it a second time on the other side so it never pops.
- Shooting a large asteroid splits it into two medium ones, a medium into two small ones, and small ones are destroyed. Keep score and start a new wave when the screen is clear.
- For collisions, test each bullet against the rock outline with a point-in-polygon check, measuring distances the short way around the wrapped screen.

Once that works, make it beautiful:
- Fake a phosphor screen: stroke every line three times with additive blending ("lighter"), first wide and faint, then medium, then thin and bright.
- Do not fully clear the canvas each frame; fade it toward black so moving lines leave a short glow.
- Add a flickering thrust flame, flying debris when things explode, and a little screen shake.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as flying saucers that shoot back, a hyperspace button, or an AI pilot that plays when nobody is at the keyboard.
PreviousSeismic ShadowQuake waves curve through a cutaway Earth, leaving the shadows that revealed its core. NextWater RipplesRaindrops on a koi pond, with ripples that bend the scene below.

Related visualizations

  • Moon LanderRetro Vector-line lunar descent on a green phosphor tube, with a suicide-burn autopilot.
  • BreakoutGames The arcade classic, with sparks, screen shake and an autopilot.
  • Bubble Bank ShooterGames A pastel bubble shooter whose AI traces 640 bank shots before every throw.
  • CRT MonitorRetro An emulated electron beam, decaying phosphors and a shadow mask, under a 7x loupe.
  • Vector BallsRetro 512 chrome spheres, depth sorted, morphing from a torus knot to DNA to a smiling face.
  • Oscilloscope MusicRetro A phosphor XY scope draws a 4D tesseract, knots and text from the stereo sound you hear.
  • Pool Trick ShotsGames Billiards with real spin physics and an AI that plans by simulating every shot.
  • Marble LabyrinthGames A wooden tilt maze where a careful AI steers a steel ball between the holes.
  • Glenz VectorsRetro Nested glassy checkered polyhedra bounce on a glossy floor, then shatter and rebuild.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs