Build a Garden Caterpillar Snake Game with Swipe and Wrap Mode in HTML
A prompt that produces Leafline, an original snake-style game where a caterpillar eats garden leaves, with swipe controls, buffered turns, wrap mode and a speed slider.
The prompt
Act as a senior front-end game developer. Build "Leafline", an original snake-style browser game. A hungry caterpillar crawls through a kitchen garden, eats leaves and grows one segment per leaf. Use a 20x20 grid on a canvas drawn with simple shapes: a checkered grass board, a round-segmented orange caterpillar with a red head, eyes and antennae, and a green leaf with a pale vein. Rules: 1) Controls: arrow keys or WASD, swipe on the board for touch, and an on-screen four-button pad. Space or P pauses. 2) Input buffering: queue up to 3 turns and check each new turn against the last queued direction. Ignore reversals and duplicates so fast double-taps never cause a false self-collision. 3) A "Wrap edges" checkbox: when it is on, the caterpillar passes through walls; when it is off, the fence ends the run. Draw a solid fence border or a dashed open border to match. 4) A speed slider with five named levels, driven by a fixed-timestep requestAnimationFrame loop. 5) Show leaves eaten and the session best score, ready, paused and game-over overlays on the canvas, and an aria-live status line. 6) Use a cream, deep green and orange palette and a responsive square board up to 520px. Add Web Audio chomp and game-over sounds that start on first input, plus a mute button. Add a gentle leaf wobble that is turned off under prefers-reduced-motion. Use no external assets, storage or dialogs. Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.Example output
Tips and common edits
Why this works
- Turns are checked against the last queued direction rather than the current one, which removes the classic instant-reversal death bug.
- A fixed-timestep loop keeps speed consistent across devices, and the slider changes it live without restarting.
- Swipe, keyboard and button pad all feed the same queue, so every input method behaves identically.
Paste the prompt into ChatGPT, Claude or Gemini. Save the returned code as leafline.html and open it in any browser, or run it in the chat's preview or canvas panel. It works offline.
Common edits
- Change the theme: swap the caterpillar and leaves for a fish and plankton, and recolor the board to blues.
- Raise the difficulty: add rocks that appear every 5 leaves, or make the speed increase automatically as the score climbs.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Build a Four-Lane Rhythm Tap Game with a Generated Beat in One HTML File
A ready-to-paste prompt that builds a complete four-lane rhythm tap game with a live Web Audio beat, Perfect/Good/Miss timing grades, combo scoring and a results screen.
Build a Color Sequence Memory Game with Synth Tones in One HTML File
A ready-to-paste prompt that builds Echo Garden, a four-pad color-and-shape sequence memory game with Web Audio tones, a strict mode and rising speed.
Build a Gnome-Popping Whack-a-Mole Game With Decoys in One HTML File
A ready-to-paste prompt that makes an AI build Gnome Pop Garden, a fast whack-a-mole style tapping game with speed that ramps up, hedgehog decoys that cost points, and number-key controls.
Build a Reaction Time Tester Game with False-Start Detection in One HTML File
Get a polished reaction time test with random delays, false-start penalties, a five-attempt average and an SVG results chart, all in one HTML file.
Build a Tower Stacking Game with Slice-Off Blocks in a Single HTML File
A ready-to-paste prompt that builds a one-tap tower stacking game where overhangs are sliced off, perfect drops restore width, and the camera follows the tower upward.
Build a Word Scramble Puzzle Game with Hints, Categories and Streaks in HTML
A prompt that produces a single-file word scramble game with themed categories, paid letter hints, streak bonuses, and both typing and tile-tapping controls.