Claude Game Studio

How to make a browser game

Make a browser game with HTML, JavaScript and a canvas, then test its controls, rules and restart before publishing.

Start with one complete round

Parcel Sprint has one job: pick up three orange parcels and return to the blue depot. The central wall forces a route decision. A 40-second timer supplies the loss condition. That is enough to test movement, collision, pickup, a visible result and a fresh round in one small project.

Download the file above and open it in a text editor. The first script, marked id="rules", holds the game state and movement rules. The second script connects those rules to the canvas, keys and buttons. Change the parcel positions before changing the art; you can see immediately whether the new route works.

For the Claude Code route, open an empty folder and paste this brief. The downloadable example was written for this guide; the prompt describes the same finished scope.

Make a browser game called Parcel Sprint in one HTML file. Draw a top-down delivery yard on a 720 by 400 canvas. Collect three parcels and return to the depot within 40 seconds. Include one wall, keyboard and touch controls, a fixed simulation step, pause on tab hide, win, loss and restart. Use drawn shapes and no network dependencies.

Run the file locally

Save the downloaded file in a folder called parcel-sprint. This example uses ordinary scripts and draws its own art, so opening the HTML file directly is enough. When you add JavaScript modules, fetched data or external assets, serve the folder over HTTP so local-file security rules do not become a second debugging problem.

From that folder, run the command beside this paragraph and open http://localhost:8000/parcel-sprint.html. Keep the terminal open while playing. Stop the server with Ctrl+C. Your local server serves this folder; put only the game files you intend to inspect in it.

python3 -m http.server 8000 --bind 127.0.0.1

First change: move the second parcel from x = 560 to x = 420 in PARCELS. Reload. The orange box should move while the wall, timer and depot stay in place. This small edit checks that you are serving the file you actually changed.

Connect input, rules and drawing

The frame loop reads held buttons, advances the rules in 1/120-second steps, then draws the result. MDN calls this cycle Present, accept, interpret, calculate, repeat in its game anatomy guide. Drawing follows requestAnimationFrame; movement uses elapsed time rather than assuming every monitor redraws at the same speed.

The order matters. A pickup checks the player's updated position. The win check follows pickup, so collecting the last parcel beside the depot can finish the round immediately. Drawing comes last and reads that same state. Avoid moving the player in both the keyboard handler and the frame loop, which would give two different paths responsibility for one action.

  1. 1. Read: arrows, WASD or the pressed touch button.
  2. 2. Move: normalize the direction, then check each axis against the wall.
  3. 3. Resolve: collect nearby parcels; finish on depot return or timeout.
  4. 4. Draw: yard, wall, remaining parcels, courier and round result.

There is no art-loading stage here. Adding an image later means loading it once before Play, then reusing it while drawing.

Fix movement through thin walls

One large movement update crosses the wall; 120 small updates stop the courier before it.WallOne update: x = 430120 steps: x = 287.5Same start x = 250 · same 1 second of movement
Node ran the game's actual movement function. The courier moves 180 pixels per second; its radius is 12 pixels. The wall begins at x = 300. Checking only the destination misses a wall crossed between frames. Open the inputs and results.

The test starts the courier at x = 250, facing a wall at x = 300. One movement update for an entire second lands at x = 430, beyond the wall, so a destination-only check incorrectly accepts it. Running the same second as 120 small steps stops at x = 287.5. Those are actual results from the downloadable game's movement code.

Use the accumulator in the example when adapting it. A frame contributes elapsed time, and the simulation consumes fixed steps until it catches up. The example also limits one frame's catch-up to a quarter second and pauses on tab hide. That is a policy for this small game: the player resumes the round deliberately instead of returning to a timer that expired off-screen.

For a fast projectile, use a swept collision test along its traveled segment. Smaller steps alone do not guarantee that an arbitrarily fast object cannot cross a thin obstacle. Keep the illustrated test when changing player speed or wall thickness.

Test the browser, then publish

Hold two movement keys to check diagonal speed, release them outside the frame, switch tabs and return, then play to both endings. The example clears held input on blur and pointer cancellation. That prevents a released touch button or an unfocused window from leaving the courier moving. Restart must restore all three parcels as well as the timer.

The scripted route in our simulation results collects every parcel and returns to the depot in 9.10 seconds of game time. It is a known route for checking the rules. Your first human run can take longer because you are learning the yard. Use the route to separate an impossible level from a navigation mistake.

Draw simple shapes until the rules work. When adding sprites, Google's canvas performance guide recommends pre-rendering repeated drawing work and reducing unnecessary state changes. A background that stays still can be prepared once; the courier and parcels still need to update. Measure your actual game before replacing clear code with an optimization.

To publish this example, rename a copy to index.html and upload it to a static host. Open the resulting HTTPS URL and finish another round there. If you add images, sound or modules, upload their relative paths too. For a larger game with asset packs and a tested starting point, the Claude Game Studio kit supplies the next project; the AI guide shows its actual Burning Thatch build.

Questions

How do I make a browser game?

Create an HTML page with a canvas, add input and a game loop in JavaScript, then give the player a goal, a loss condition and a restart. Parcel Sprint on this page is a complete example you can download and change.

How do I make a game in HTML?

HTML supplies the canvas and buttons; JavaScript moves the player, checks collisions and draws each frame. Save the example as parcel-sprint.html. It has no external libraries, so it can open directly or through a local web server.

Can I make a browser game with Claude Code?

Yes. Open a project folder, give Claude Code a bounded brief and ask it to save a working HTML file. Use this page's prompt and check the wall, tab pause, win, loss and restart before adding more features.

How do I publish an HTML5 game?

Put the exported HTML file and every required asset on a static host with HTTPS. Name the entry file index.html when the host expects a directory entry. Open the published URL in a fresh tab and test the complete round again.