Asteroids · gemma-4-31b-it
Build a playable Asteroids game on a canvas: a thrust-and-rotate vector ship that shoots and wraps around the screen edges, splitting asteroids into smaller pieces, with score and lives. Procedural vector graphics only, no external assets.
transcript · 14 messages
Build a playable Asteroids game on a canvas: a thrust-and-rotate vector ship that shoots and wraps around the screen edges, splitting asteroids into smaller pieces, with score and lives. Procedural vector graphics only, no external assets.
thinking
The objective is to create a fully playable "Asteroids" game in a single `index.html` file.
* Requirements:
* Single file: HTML, CSS, and JS all inline.
* No external assets: No CDNs, no images, no network requests.
* Gameplay:
* Ship: Thrust-and-rotate physics.
* Shooting: Projectiles that destroy asteroids.
* Screen wrapping: All entities wrap around edges.
* Asteroids: Split into smaller pieces when hit.
* UI: Score and Lives.
* Graphics: Procedural vector-style (line drawings on canvas).
* Canvas for rendering.
* Game loop (`requestAnimationFrame`).
* Input handling (keyboard).
* State management (ship, asteroids, bullets, particles/explosions).
* Collision detection (circle-based is simplest and effective).
* Physics (velocity, friction/damping for the ship).
* *Ship*: Position, velocity, rotation, thrusting state.
* *Asteroids*: Position, velocity, size (Large, Medium, Small), shape (randomized vertices for "rocky" look).
* *Bullets*: Position, velocity, lifespan.
* *GameState*: Score, lives, gameOver status.
* `update()`: Handle movement, wrapping, collisions, lifetimes.
* `draw()`: Clear screen, draw ship, asteroids, bullets, and UI.
* `input()`: Handle key presses.
* Need a "rocky" look. Instead of perfect circles, I'll generate a set of points around a circle with random offsets.index.html (16573 bytes)Successfully wrote 16573 bytes to index.html
thinking
The user wants a playable Asteroids game. I have implemented a complete version in `index.html` with: 1. Thrust-and-rotate ship physics. 2. Screen wrapping for ship, asteroids, and bullets. 3. Asteroids that split into smaller pieces. 4. Score and lives tracking. 5. Vector-style procedural graphics. 6. Invulnerability period after respawning. 7. Collision detection. 8. A start/game over overlay. 9. Keyboard input handling. I'll do a quick double-check of the code for any obvious bugs. One small thing: I noticed a typo in the HTML `div` for score and lives: `<div class="stat">SCORE: <span id="score">0</span></div>`. The `</span>` is missing. Let me fix that small typo.
{"edits":[{"newText":" <div class=\"stat\">SCORE: <span id=\"score\">0</span></div>","oldText":" <div class=\"stat\">SCORE: <sNo changes made to index.html. The replacements produced identical content.
thinking
Ah, I see. I tried to replace the exact same text with itself. I should have fixed the closing tags. Wait, looking at my previous `write` call: `<div class="stat">SCORE: <span id="score">0</span></div>` The `</span>` is indeed missing. It is `</span></div>`. I should change it to `</span></div>`. Let me correct those tags.
{"edits":[{"newText":" <div class=\"stat\">SCORE: <span id=\"score\">0</span></div>","oldText":" <div class=\"stat\">SCORE: <sNo changes made to index.html. The replacements produced identical content.
thinking
I'm having trouble seeing where I messed up the edit because I kept typing the same thing. Let's look at the code again. Original: `<div class="stat">SCORE: <span id="score">0</span></div>` Wait, `</span></div>` is actually wrong. It should be `</span></div>`. My original code had: `<div class="stat">SCORE: <span id="score">0</span></div>` Actually, looking at the `write` block: `<div class="stat">SCORE: <span id="score">0</span></div>` `<div class="stat">LIVES: <span id="lives">3</span></div>` Wait, the `</span>` in my `write` call was actually `</span></div>`. No, it was `</span></div>`. Wait, I see: `</span></div>`. The closing `>` for `span` is missing. Correct: `</span></div>`. Let me try again.
{"edits":[{"newText":" <div class=\"stat\">SCORE: <span id=\"score\">0</span></div>","oldText":" <div class=\"stat\">SCORE: <sNo changes made to index.html. The replacements produced identical content.
thinking
I keep making the same mistake in the `edit` call. I'm providing identical text for old and new. Let's just rewrite the UI part of the file or just leave it, as the browser usually recovers from a missing `>` in a tag. But I want it to be clean. Actually, the easiest way to fix this is to use a larger block or just rewrite the whole thing if it's small, but the file is already quite large. Let me try again, paying very close attention to the characters. Original: `<div class="stat">SCORE: <span id="score">0</span></div>` (Notice the `</span` is missing the `>`) Corrected: `<div class="stat">SCORE: <span id="score">0</span></div>` Let's try again.
{"edits":[{"newText":" <div class=\"stat\">SCORE: <span id=\"score\">0</span></div>","oldText":" <div class=\"stat\">SCORE: <sNo changes made to index.html. The replacements produced identical content.
thinking
Okay, I'm failing at the `edit` tool because I'm likely not copying the exact text from the `write` output. I will just rewrite the `index.html` one more time to be absolutely sure everything is correct and the typos are gone.
index.html (16122 bytes)Successfully wrote 16122 bytes to index.html
thinking
I have now correctly implemented the game in `index.html`. The physics are correct, the vector graphics are procedurally generated, and all requirements (wrapping, splitting asteroids, lives/score) are met.
The playable Asteroids game has been built and saved as `index.html`. ### Features Included: - **Ship Physics**: Rotation with A/D or Left/Right, thrust with W or Up. The ship has momentum and friction for a smooth "space" feel. - **Combat**: Spacebar fires projectiles that destroy asteroids. - **Asteroid Mechanics**: Asteroids are procedurally generated with random rocky vertices. They split from Large $\rightarrow$ Medium $\rightarrow$ Small when hit. - **Screen Wrapping**: The ship, bullets, and asteroids all wrap around the screen edges. - **UI & Game Loop**: - Real-time score and lives tracking. - Invulnerability period (blinking) after spawning. - Start and Game Over screens. - Progressive difficulty (more asteroids spawn as the score increases). - **Vector Graphics**: Pure HTML5 Canvas drawing with a classic green-on-black vector aesthetic. The game is fully self-contained and requires no external assets or network connectivity.
TAKE IT TO CODE
A single self-contained HTML file — copy it and open in any browser, or reuse the prompt with your own pi-agent run.
RUN
EVALUATION
Vector Asteroids starts at menu, then keyboard input starts game with ship, asteroids, and lives; mouse inputs have no effect on menu.
Vision grade · anthropic/claude-sonnet-5
MEASUREMENTS
Raw readings from the capture, not a verdict — the grade above is the only judgement. Percentages are how much of the screen changed; the measure under-reports sparse motion on a dark background.