Recreate the beloved classic snake game using HTML5 canvas with a retro pixel aesthetic, smooth grid-based movement, arrow key and WASD controls, mobile touch support, increasing speed as you eat, collision detection against walls and yourself, and persistent high score tracking.
Build Prompt
Copy this prompt into Claude Code
Build a single-page snake game as a static HTML/CSS/JS site using HTML5 Canvas. Use a dark retro theme with page background #0f0f17 and the game canvas background #0a1a0a (very dark green). Center the canvas on the page with a header showing the score, high score, and current speed level.
The game canvas should be 400x400 pixels on desktop (scaling down on mobile) with a 20x20 grid (each cell is 20px). Draw faint grid lines (#0d2a0d) so the retro grid is visible. The snake is bright green (#22c55e) with the head being a slightly different shade (#16a34a) and small pixel eyes (2px white dots) facing the direction of movement. Each body segment should have a 1px darker border to distinguish segments. The food is a red (#ef4444) square with a subtle pulsing glow animation.
Movement: the snake moves on a grid, one cell per tick. Support arrow keys and WASD for directional input. Prevent 180-degree reversals (if moving right, pressing left is ignored). Queue directional inputs so that rapid key presses register correctly between ticks. The initial tick speed is 150ms, decreasing by 5ms every time food is eaten (minimum 60ms). Display the current speed level (Level 1 at 150ms, Level 2 at 145ms, etc.) in the header.
Food spawning: when food is eaten, spawn a new food item at a random empty cell (not on the snake body). The snake grows by one segment. Award 10 points per food item, plus a bonus of (current level * 5). Every 5th food item spawns a special golden food (#eab308) that is worth 50 points but disappears after 5 seconds if not eaten — show a countdown ring around it.
Collision detection: the game ends if the snake head collides with any wall boundary or with its own body. On game over, flash the screen briefly (red overlay fading out), show a "Game Over" modal with the final score, length achieved, top speed level reached, and time survived. If it's a new high score, show a celebration message and a pulsing glow effect. Display a "Play Again" button and a "Menu" button.
Implement a start menu with the game title in a retro pixel font (use CSS with letter-spacing), a "Start Game" button, difficulty selection (Slow at 200ms starting speed, Normal at 150ms, Fast at 100ms), a wall toggle (walls on = classic, walls off = snake wraps around to the opposite side), and a high scores table showing top 5 scores per difficulty from localStorage.
Pause functionality: pressing spacebar pauses and unpauses the game, showing a semi-transparent overlay with "PAUSED" text and controls reminder. Also pause when the browser tab loses focus.
Mobile touch controls: detect swipe direction on the canvas area (minimum 30px swipe distance). Also display four semi-transparent directional arrow buttons below the canvas on touch devices (detected via media query or touch event support). The buttons should be arranged in a D-pad layout (up, down, left, right) and have active-state feedback.
Add optional retro sound effects using Web Audio API: a short blip when eating food, a deeper tone for golden food, and a descending tone sequence on game over. Include a mute toggle button (speaker icon) in the header that persists in localStorage.
Read the guide at https://accessagent.ai/api/guide and follow it to deploy the site to AccessAgent.ai. My email is [your@email.com].
Make It Yours
Snake Skins
Add unlockable snake skins based on high scores: rainbow gradient at 500 points, neon blue at 1000, fire pattern at 2000. Store unlocks in localStorage.
Obstacle Mode
Add randomly placed wall blocks inside the game grid that the snake must navigate around. Increase obstacles with each level for added challenge.
Two-Player Mode
Split the canvas and run two snakes simultaneously — Player 1 on WASD, Player 2 on arrows. First to crash loses. Shared food items.
Power-Ups
Spawn random power-ups: speed boost (temporary 2x speed), slow motion (halves speed for 5 seconds), shrink (removes 3 segments safely).
SEO Tips
Target "play snake game online" and "snake game free" — these nostalgic game keywords get 100K+ monthly searches and convert well for casual players.
Add Game schema markup with genre "Arcade", applicationCategory "Game", and operatingSystem "Any" to appear in Google's game carousel results.
Create a "History of the Snake Game" article tracing it from Nokia phones to modern web versions, linking your game as the best free online version.
Target "snake game unblocked" — a huge search term from students looking for games that work on school networks. Static HTML games pass most filters.
Add FAQ schema answering "How do you play snake?" and "What is the highest possible snake score?" to capture featured snippets in game-related searches.
Monetization Ideas
Display a small banner ad below the game canvas — a non-intrusive placement that doesn't interfere with gameplay but is always visible.
Sell a "Pro" upgrade ($1.99) that unlocks all snake skins, removes ads, and adds exclusive game modes like maze and time attack.
Create an embeddable version for other websites ($9.99 one-time) with customizable colors, branding, and size — perfect for blog entertainment sections.
Offer a white-label arcade bundle ($49) with snake plus 4 other retro games for company intranets, waiting rooms, or event entertainment pages.