Create an snail-themed arcade game in a coding language of your choosing. Do not rely on…
- User
Create an snail-themed arcade game in a coding language of your choosing. Do not rely on external file uploads and instead create your own assets and designs.
Assistant
Of course! Here is a complete, self-contained, snail-themed arcade game called "Snail Trail: The Great Lettuce Heist".
This game is written in HTML, CSS, and JavaScript. It runs directly in your browser with no need for external libraries or file uploads. All the visual assets—the snail, lettuce, salt, birds, and even the background—are drawn procedurally using the HTML5 Canvas API.
How to Play
- Save the code: Copy the code below into a single text file and save it as
snail_game.html. - Open in browser: Open the
snail_game.htmlfile in any modern web browser (like Chrome, Firefox, or Edge). - Controls:
- Use the Arrow Keys to move the snail.
- The goal is to collect all the green lettuce leaves on each level.
- Avoid the Hazards:
- Salt Piles: Touching these will cost you a life.
- Swooping Birds: These patrol the garden. Getting hit will also cost you a life.
- Scoring:
- You get 10 points for each lettuce collected.
- You get a 50-point bonus for completing a level.
- The game gets progressively harder with each level!
The Code (
snail_game.html)<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Snail Trail: The Great Lettuce Heist</title> <style> body { background-color: #333; color: #fff; font-family: 'Courier New', Courier, monospace; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; text-align: center; } h1 { color: #9dffb0; text-shadow: 2px 2px 4px #000; } canvas { background-color: #78a364; /* Garden green */ border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.5); cursor: pointer; } #ui-container { position: relative; } #overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); display: flex; flex-direction: column; justify-content: center; align-items: center; border-radius: 10px; transition: opacity 0.5s; } #overlay.hidden { opacity: 0; pointer-events: none; } #overlay h2 { font-size: 2.5em; margin-bottom: 10px; } #overlay p { font-size: 1.2em; max-width: 80%; } #overlay button { font-size: 1.5em; padding: 10px 20px; background-color: #ffde59; color: #4a2d04; border: 2px solid #4a2d04; border-radius: 5px; cursor: pointer; margin-top: 20px; font-weight: bold; } </style> </head> <body> <h1>Snail Trail: The Great Lettuce Heist</h1> <div id="ui-container"> <canvas id="gameCanvas" width="800" height="600"></canvas> <div id="overlay"> <h2 id="overlay-title">Ready to crawl?</h2> <p id="overlay-text">Use the Arrow Keys to collect all the lettuce.<br>Avoid the salt piles and swooping birds!</p> <p id="final-score" style="display: none;"></p> <button id="startButton">Start Game</button> </div> </div> <p>Score: <span id="score">0</span> | Lives: <span id="lives">3</span> | Level: <span id="level">1</span></p> <script> // =================================== // GAME SETUP // =================================== const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const scoreEl = document.getElementById('score'); const livesEl = document.getElementById('lives'); const levelEl = document.getElementById('level'); const overlay = document.getElementById('overlay'); const overlayTitle = document.getElementById('overlay-title'); const overlayText = document.getElementById('overlay-text'); const finalScoreEl = document.getElementById('final-score'); const startButton = document.getElementById('startButton'); let gameState = { score: 0, lives: 3, level: 1, isGameOver: true, isPaused: true, player: null, lettuces: [], hazards: [], keys: { ArrowUp: false, ArrowDown: false, ArrowLeft: false, ArrowRight: false } }; // =================================== // GAME ASSET DRAWING FUNCTIONS // =================================== function drawSnail(x, y, direction) { ctx.save(); ctx.translate(x, y); // Eye wiggle based on movement let eyeOffsetX = 0; let eyeOffsetY = 0; if (gameState.keys.ArrowRight) eyeOffsetX = 2; if (gameState.keys.ArrowLeft) eyeOffsetX = -2; if (gameState.keys.ArrowUp) eyeOffsetY = -2; if (gameState.keys.ArrowDown) eyeOffsetY = 2; // Eyestalks ctx.strokeStyle = '#c2b280'; // Fawn color ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(-5, -15); ctx.lineTo(-8 + eyeOffsetX, -25 + eyeOffsetY); ctx.moveTo(5, -15); ctx.lineTo(8 + eyeOffsetX, -25 + eyeOffsetY); ctx.stroke(); // Eyes ctx.fillStyle = 'black'; ctx.beginPath(); ctx.arc(-8 + eyeOffsetX, -25 + eyeOffsetY, 3, 0, Math.PI * 2); ctx.arc(8 + eyeOffsetX, -25 + eyeOffsetY, 3, 0, Math.PI * 2); ctx.fill(); // Body ctx.fillStyle = '#d4e29e'; // Light yellowish green ctx.strokeStyle = '#85906a'; ctx.lineWidth = 2; ctx.beginPath(); ctx.ellipse(0, 0, 20, 15, 0, Math.PI, Math.PI * 2, true); ctx.closePath(); ctx.fill(); ctx.stroke(); // Shell ctx.fillStyle = '#8b5a2b'; // Brown ctx.strokeStyle = '#4a2d04'; // Dark brown ctx.lineWidth = 3; ctx.beginPath(); let radius = 18; let angle = 0; ctx.moveTo(0, -15); for (let i = 0; i < 150; i++) { angle += 0.1; radius *= 0.985; ctx.lineTo(radius * Math.cos(angle), -15 + radius * Math.sin(angle)); } ctx.stroke(); ctx.fill(); ctx.restore(); } function drawLettuce(x, y) { ctx.save(); ctx.translate(x, y); ctx.fillStyle = '#5ca342'; // Lettuce green ctx.strokeStyle = '#3e702c'; // Darker green ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(0, -15); ctx.quadraticCurveTo(15, -25, 20, -10); ctx.quadraticCurveTo(25, 10, 10, 15); ctx.quadraticCurveTo(0, 25, -10, 15); ctx.quadraticCurveTo(-25, 10, -20, -10); ctx.quadraticCurveTo(-15, -25, 0, -15); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); } function drawSalt(x, y) { ctx.save(); ctx.translate(x, y); const colors = ['rgba(255, 255, 255, 0.8)', 'rgba(240, 240, 255, 0.7)', 'rgba(230, 230, 240, 0.9)']; for (let i = 0; i < 15; i++) { ctx.fillStyle = colors[i % colors.length]; const r = 5 + Math.random() * 10; const offsetX = (Math.random() - 0.5) * 30; const offsetY = (Math.random() - 0.5) * 20; ctx.beginPath(); ctx.arc(offsetX, offsetY, r, 0, Math.PI * 2); ctx.fill(); } ctx.restore(); } function drawBird(x, y) { ctx.save(); ctx.translate(x, y); ctx.fillStyle = '#333333'; ctx.strokeStyle = '#111111'; ctx.lineWidth = 2; // Wings ctx.beginPath(); ctx.moveTo(0, 0); ctx.lineTo(-25, -10); ctx.lineTo(-15, 0); ctx.lineTo(0, 5); ctx.lineTo(15, 0); ctx.lineTo(25, -10); ctx.lineTo(0, 0); ctx.closePath(); ctx.fill(); ctx.stroke(); ctx.restore(); } // =================================== // GAME OBJECT CLASSES // =================================== class Entity { constructor(x, y, radius) { this.x = x; this.y = y; this.radius = radius; } draw() { /* To be implemented by subclasses */ } update() { /* To be implemented by subclasses */ } } class Player extends Entity { constructor(x, y) { super(x, y, 20); // Collision radius this.speed = 2; this.direction = 'right'; } update() { if (gameState.keys.ArrowUp && this.y > this.radius) this.y -= this.speed; if (gameState.keys.ArrowDown && this.y < canvas.height - this.radius) this.y += this.speed; if (gameState.keys.ArrowLeft && this.x > this.radius) this.x -= this.speed; if (gameState.keys.ArrowRight && this.x < canvas.width - this.radius) this.x += this.speed; } draw() { drawSnail(this.x, this.y, this.direction); } } class Lettuce extends Entity { constructor(x, y) { super(x, y, 15); } draw() { drawLettuce(this.x, this.y); } } class Hazard extends Entity { constructor(x, y, radius) { super(x, y, radius); } } class Salt extends Hazard { constructor(x, y) { super(x, y, 25); } draw() { drawSalt(this.x, this.y); } } class Bird extends Hazard { constructor(y, speed) { const startX = speed > 0 ? -30 : canvas.width + 30; super(startX, y, 20); this.speed = speed; } update() { this.x += this.speed; // Reset bird when it goes off-screen if (this.speed > 0 && this.x > canvas.width + 40) { this.x = -40; } else if (this.speed < 0 && this.x < -40) { this.x = canvas.width + 40; } } draw() { drawBird(this.x, this.y); } } // =================================== // GAME LOGIC // =================================== function updateUI() { scoreEl.textContent = gameState.score; livesEl.textContent = gameState.lives; levelEl.textContent = gameState.level; } function initLevel(level) { gameState.lettuces = []; gameState.hazards = []; const lettuceCount = 5 + level; for (let i = 0; i < lettuceCount; i++) { const x = 50 + Math.random() * (canvas.width - 100); const y = 50 + Math.random() * (canvas.height - 100); gameState.lettuces.push(new Lettuce(x, y)); } const saltCount = level * 2; for (let i = 0; i < saltCount; i++) { const x = 100 + Math.random() * (canvas.width - 200); const y = 100 + Math.random() * (canvas.height - 200); gameState.hazards.push(new Salt(x, y)); } const birdCount = Math.floor(level / 2) + 1; for (let i = 0; i < birdCount; i++) { const y = 50 + Math.random() * (canvas.height - 100); const speed = (2 + level * 0.5) * (Math.random() < 0.5 ? 1 : -1); gameState.hazards.push(new Bird(y, speed)); } } function checkCollisions() { const player = gameState.player; // Player vs Lettuce gameState.lettuces.forEach((lettuce, index) => { const dist = Math.hypot(player.x - lettuce.x, player.y - lettuce.y); if (dist < player.radius + lettuce.radius) { gameState.lettuces.splice(index, 1); gameState.score += 10; updateUI(); if (gameState.lettuces.length === 0) { levelUp(); } } }); // Player vs Hazards gameState.hazards.forEach(hazard => { const dist = Math.hypot(player.x - hazard.x, player.y - hazard.y); if (dist < player.radius + hazard.radius) { handlePlayerHit(); } }); } function handlePlayerHit() { gameState.lives--; updateUI(); if (gameState.lives <= 0) { gameOver(); } else { // Reset player position after a brief pause gameState.isPaused = true; setTimeout(() => { gameState.player.x = canvas.width / 2; gameState.player.y = canvas.height - 50; gameState.isPaused = false; gameLoop(); }, 500); } } function levelUp() { gameState.level++; gameState.score += 50; // Level complete bonus gameState.isPaused = true; overlayTitle.textContent = `Level ${gameState.level-1} Complete!`; overlayText.textContent = `Get ready for Level ${gameState.level}...`; finalScoreEl.style.display = 'none'; startButton.textContent = 'Next Level'; overlay.classList.remove('hidden'); // Button will restart the loop } function gameOver() { gameState.isGameOver = true; gameState.isPaused = true; overlayTitle.textContent = 'Game Over'; overlayText.textContent = 'The garden was too perilous!'; finalScoreEl.textContent = `Final Score: ${gameState.score}`; finalScoreEl.style.display = 'block'; startButton.textContent = 'Play Again'; overlay.classList.remove('hidden'); } function startGame() { Object.assign(gameState, { score: 0, lives: 3, level: 1, isGameOver: false, isPaused: false, player: new Player(canvas.width / 2, canvas.height - 50), lettuces: [], hazards: [], }); overlay.classList.add('hidden'); initLevel(gameState.level); updateUI(); gameLoop(); } function startNextLevel() { gameState.isPaused = false; overlay.classList.add('hidden'); gameState.player.x = canvas.width / 2; gameState.player.y = canvas.height - 50; initLevel(gameState.level); updateUI(); gameLoop(); } // =================================== // MAIN GAME LOOP // =================================== function gameLoop() { if (gameState.isPaused) { return; // Stop the loop if paused or game over } // 1. Update state gameState.player.update(); gameState.hazards.forEach(h => h.update && h.update()); // Only update moving hazards checkCollisions(); // 2. Draw everything ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw background details (procedural grass blades) for(let i=0; i<100; i++){ const x = Math.random() * canvas.width; const y = Math.random() * canvas.height; const height = 5 + Math.random() * 10; ctx.strokeStyle = `rgba(50, 100, 50, 0.4)`; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x, y - height); ctx.stroke(); } gameState.lettuces.forEach(l => l.draw()); gameState.hazards.forEach(h => h.draw()); gameState.player.draw(); // 3. Request next frame requestAnimationFrame(gameLoop); } // =================================== // EVENT LISTENERS // =================================== window.addEventListener('keydown', e => { if (gameState.keys.hasOwnProperty(e.key)) { e.preventDefault(); gameState.keys[e.key] = true; } }); window.addEventListener('keyup', e => { if (gameState.keys.hasOwnProperty(e.key)) { e.preventDefault(); gameState.keys[e.key] = false; } }); startButton.addEventListener('click', () => { if (gameState.isGameOver) { startGame(); } else { // This handles the 'Next Level' button startNextLevel(); } }); </script> </body> </html>- Save the code: Copy the code below into a single text file and save it as
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.