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

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

One HTML file. Save it and open it in any browser.Open full screen

Example: Leafline, a garden caterpillar game in the snake genre.

Press an arrow key, use WASD, swipe the board or tap the on-screen pad to start crawling. Each leaf adds a segment and a point, and your session best is shown at the top. Turn on Wrap edges to tunnel through the fence. Drag the speed slider from Snooze up to Dash. Try fast double-turns: they are buffered, so you won't bite your own tail by accident. Space or P pauses, and the mute button silences the chomps.

Written by AI from this prompt. Your results will vary.

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 in Simple HTML Games