Create a working website snake game, with a twist
- User
Create a working website snake game, with a twist
Assistant
I'll create a Snake game with a twist - the snake changes colors as it grows, and there are special power-up foods that give different abilities!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Rainbow Snake Game</title> <style> body { margin: 0; padding: 20px; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); font-family: Arial, sans-serif; } .game-container { text-align: center; background: rgba(255, 255, 255, 0.1); padding: 20px; border-radius: 15px; backdrop-filter: blur(10px); } canvas { border: 3px solid #fff; border-radius: 10px; background: #000; } .score { color: white; font-size: 24px; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.5); } .controls { color: white; margin-top: 15px; font-size: 14px; } .power-info { color: #ffeb3b; margin-top: 10px; font-size: 16px; min-height: 20px; } </style> </head> <body> <div class="game-container"> <div class="score">Score: <span id="score">0</span></div> <canvas id="gameCanvas" width="400" height="400"></canvas> <div class="power-info" id="powerInfo"></div> <div class="controls"> Use WASD or Arrow Keys to move<br> 🔴 Red food = Speed boost | 🟡 Yellow food = Phase through walls | 🟢 Green food = Normal </div> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const scoreElement = document.getElementById('score'); const powerInfo = document.getElementById('powerInfo'); const gridSize = 20; const tileCount = canvas.width / gridSize; let snake = [ {x: 10, y: 10} ]; let food = {}; let dx = 0; let dy = 0; let score = 0; let gameRunning = true; // Power-up system let speedBoost = false; let phaseMode = false; let powerUpTimer = 0; // Rainbow colors for snake segments const rainbowColors = [ '#ff0000', '#ff7f00', '#ffff00', '#00ff00', '#0000ff', '#4b0082', '#9400d3', '#ff1493' ]; function randomTilePosition() { return { x: Math.floor(Math.random() * tileCount), y: Math.floor(Math.random() * tileCount) }; } function generateFood() { food = randomTilePosition(); // Random food type: 0 = normal (green), 1 = speed boost (red), 2 = phase mode (yellow) food.type = Math.floor(Math.random() * 3); } function drawGame() { // Clear canvas ctx.fillStyle = 'black'; ctx.fillRect(0, 0, canvas.width, canvas.height); // Draw snake with rainbow effect snake.forEach((segment, index) => { ctx.fillStyle = rainbowColors[index % rainbowColors.length]; ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize - 2, gridSize - 2); // Add glow effect ctx.shadowColor = rainbowColors[index % rainbowColors.length]; ctx.shadowBlur = 10; ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize - 2, gridSize - 2); ctx.shadowBlur = 0; }); // Draw food with different colors based on type let foodColor; switch(food.type) { case 0: foodColor = '#00ff00'; break; // Green - normal case 1: foodColor = '#ff0000'; break; // Red - speed boost case 2: foodColor = '#ffff00'; break; // Yellow - phase mode } ctx.fillStyle = foodColor; ctx.shadowColor = foodColor; ctx.shadowBlur = 15; ctx.fillRect(food.x * gridSize, food.y * gridSize, gridSize - 2, gridSize - 2); ctx.shadowBlur = 0; } function moveSnake() { const head = {x: snake[0].x + dx, y: snake[0].y + dy}; // Phase mode allows going through walls if (phaseMode) { if (head.x < 0) head.x = tileCount - 1; if (head.x >= tileCount) head.x = 0; if (head.y < 0) head.y = tileCount - 1; if (head.y >= tileCount) head.y = 0; } else { // Normal wall collision if (head.x < 0 || head.x >= tileCount || head.y < 0 || head.y >= tileCount) { gameRunning = false; alert('Game Over! Final Score: ' + score); resetGame(); return; } } snake.unshift(head); // Check food collision if (head.x === food.x && head.y === food.y) { score += 10; scoreElement.textContent = score; // Apply power-up effects switch(food.type) { case 1: // Speed boost speedBoost = true; powerUpTimer = 100; // 5 seconds at 20fps powerInfo.textContent = "🔥 SPEED BOOST ACTIVE!"; break; case 2: // Phase mode phaseMode = true; powerUpTimer = 100; powerInfo.textContent = "👻 PHASE MODE ACTIVE!"; break; default: powerInfo.textContent = ""; } generateFood(); } else { snake.pop(); } // Check self collision (unless in phase mode) if (!phaseMode) { for (let i = 4; i < snake.length; i++) { if (head.x === snake[i].x && head.y === snake[i].y) { gameRunning = false; alert('Game Over! Final Score: ' + score); resetGame(); return; } } } } function updatePowerUps() { if (powerUpTimer > 0) { powerUpTimer--; if (powerUpTimer === 0) { speedBoost = false; phaseMode = false; powerInfo.textContent = ""; } } } function gameLoop() { if (!gameRunning) return; updatePowerUps(); moveSnake(); drawGame(); // Adjust game speed based on power-ups const gameSpeed = speedBoost ? 50 : 150; setTimeout(gameLoop, gameSpeed); } function resetGame() { snake = [{x: 10, y: 10}]; dx = 0; dy = 0; score = 0; scoreElement.textContent = score; speedBoost = false; phaseMode = false; powerUpTimer = 0; powerInfo.textContent = ""; generateFood(); gameRunning = true; gameLoop(); } // Keyboard controls document.addEventListener('keydown', (e) => { if (!gameRunning) return; const key = e.key.toLowerCase(); // Prevent reverse direction if ((key === 'arrowleft' || key === 'a') && dx !== 1) { dx = -1; dy = 0; } if ((key === 'arrowright' || key === 'd') && dx !== -1) { dx = 1; dy = 0; } if ((key === 'arrowup' || key === 'w') && dy !== 1) { dx = 0; dy = -1; } if ((key === 'arrowdown' || key === 's') && dy !== -1) { dx = 0; dy = 1; } }); // Initialize game generateFood(); gameLoop(); </script> </body> </html>This Snake game includes several exciting twists:
🌈 Rainbow Snake: Each segment of the snake displays a different color from the rainbow spectrum with a glowing effect.
🎯 Power-Up Foods: Three types of food with special abilities:
- Green (Normal): Standard food that just grows the snake
- Red (Speed Boost): Makes the snake move faster for 5 seconds
- Yellow (Phase Mode): Allows the snake to pass through walls and itself for 5 seconds
✨ Visual Effects: The game features a beautiful gradient background, glowing effects, and a modern glass-morphism design.
🎮 Controls: Use WASD or arrow keys to control the snake.
The game maintains the classic Snake mechanics while adding these fun power-ups that create strategic decisions - do you go for the risky power-up food or play it safe? The rainbow effect makes it visually appealing and the power-ups add replay value!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.