Sure! I'll enhance your Cyber-Neon Snake game to make it 5× more visually appealing by:
html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Cyber-Neon Snake v2 - Ultra Neon Edition</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700&family=Share+Tech+Mono&display=swap');
/* Reset & Base */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
overflow: hidden;
user-select: none;
background:
linear-gradient(270deg, #0f2027, #203a43, #2c5364, #0f2027, #203a43, #2c5364);
background-size: 1200% 1200%;
animation: bgShift 60s ease infinite;
font-family: 'Share Tech Mono', monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #00ffbbcc;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
height: 100vh;
padding: 15px;
overflow: hidden;
}
@keyframes bgShift {
0% {background-position:0% 50%;}
50% {background-position:100% 50%;}
100% {background-position:0% 50%;}
}
/* Main Container */
#container {
display: flex;
flex-direction: column;
align-items: center;
max-width: 100vmin;
width: 100vmin;
user-select: none;
}
/* Game Frame w/ neon glass */
#game {
position: relative;
width: 100vmin;
height: 100vmin;
background: rgba(10, 20, 30, 0.8);
border: 6px solid #00ffbb;
border-radius: 30px;
box-shadow:
inset 0 0 40px 3px #00ffbbaa,
0 0 50px 4px #00ffbb66;
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
overflow: hidden;
touch-action: none;
transition: box-shadow 0.3s ease;
}
#game:focus-within {
box-shadow:
inset 0 0 80px 6px #00ffbbcc,
0 0 80px 8px #00ffbbcc;
outline: none;
}
canvas {
display: block;
width: 100%;
height: 100%;
border-radius: 25px;
image-rendering: pixelated;
background: radial-gradient(circle at center, #111722 0%, #081019 100%);
box-shadow: inset 0 0 40px #00ffbbcc;
}
/* Neon Scoreboard */
#scoreboard {
margin-top: 22px;
font-family: 'Orbitron', 'Share Tech Mono', monospace;
font-size: min(3vw, 2.5rem);
font-weight: 900;
color: #00ffbb;
text-shadow:
0 0 8px #00ffbb,
0 0 24px #00ffbb,
0 0 40px #00ffbb,
0 0 60px #00ffbb;
letter-spacing: 0.1em;
user-select: none;
position: relative;
width: 100%;
text-align: center;
filter: drop-shadow(0 0 4px #00ffbb);
animation: neonFlicker 4s infinite alternate ease-in-out;
}
@keyframes neonFlicker {
0%, 100% {
text-shadow:
0 0 5px #00ffbb,
0 0 10px #00ffbb,
0 0 20px #00ffbb,
0 0 40px #00ffbb,
0 0 80px #0ff;
color: #00ffcc;
}
20%, 40%, 60%, 80% {
text-shadow:
0 0 20px #00ffaa99,
0 0 40px #00ffaa88,
0 0 60px #00ffaa66;
color: #007755cc;
}
}
#scoreboard span.score-current {
color: #00fff9;
font-weight: 900;
text-shadow:
0 0 12px #00fff9,
0 0 30px #00fff9,
0 0 60px #00fff9;
}
#scoreboard span.score-high {
color: #66ffcc;
}
/* Controls */
#controls {
margin-top: 24px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 3rem 3rem 3rem;
gap: 15px;
width: 100vmin;
max-width: 420px;
user-select: none;
justify-items: center;
}
.btn {
background: #00ffbb;
border: none;
border-radius: 14px;
padding: 12px 0;
font-size: 1.8rem;
font-weight: 900;
color: #002200;
cursor: pointer;
box-shadow:
0 0 15px #00ffbb,
inset 0 0 15px #00ffbb;
outline-offset: 3px;
outline-color: transparent;
outline-style: solid;
transition:
background 0.3s ease,
box-shadow 0.3s ease,
transform 0.12s ease;
user-select: none;
display: flex;
align-items: center;
justify-content: center;
}
.btn:focus-visible {
outline-color: #00ffcc;
box-shadow:
0 0 20px #00ffcc,
inset 0 0 30px #00ffcc;
}
.btn:hover {
background: #00ffdd;
box-shadow:
0 0 25px #00ffdd,
inset 0 0 25px #00ffdd;
transform: scale(1.1);
}
.btn:active {
background: #00cc99;
box-shadow: inset 0 0 30px #009966;
transform: scale(0.95);
}
/* Layout grid placement for directional arrows */
#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }
/* Restart Button */
#restartBtn {
margin-top: 32px;
background: #00ffff;
color: #003333;
border-radius: 16px;
padding: 14px 0;
font-size: 1.6rem;
font-weight: 900;
box-shadow:
0 0 28px #00ffff,
inset 0 0 40px #00bbbb;
cursor: pointer;
user-select: none;
width: 100vmin;
max-width: 420px;
display: none;
transition: background 0.3s ease, box-shadow 0.3s ease;
font-family: 'Orbitron', monospace;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#restartBtn:hover,
#restartBtn:focus-visible {
background: #00dddd;
box-shadow:
0 0 36px #00dddd,
inset 0 0 48px #009999;
outline: none;
transform: scale(1.07);
}
#restartBtn:active {
background: #009999;
box-shadow: inset 0 0 32px #006666;
transform: scale(0.96);
}
/* Accessibility hide for voice */
audio[aria-hidden="true"] {
display: none !important;
}
/* Particle canvas (overlays game) */
#particles {
pointer-events: none;
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
border-radius: 30px;
z-index: 5;
mix-blend-mode: screen;
}
/* subtle glow trail */
#trailCanvas {
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
border-radius: 30px;
z-index: 4;
pointer-events: none;
image-rendering: pixelated;
}
/* Utility */
.hidden { display: none !important; }
</style>
</head>
<body>
<div id="container" role="main" aria-label="Cyber-Neon Snake Game">
<section id="game" role="region" aria-label="Snake game area" tabindex="0">
<canvas id="canvas" aria-live="polite" aria-label="Game canvas" width="600" height="600" tabindex="0"></canvas>
<canvas id="trailCanvas" width="600" height="600" aria-hidden="true"></canvas>
<canvas id="particles" width="600" height="600" aria-hidden="true"></canvas>
</section>
<div id="controls" aria-label="Directional controls">
<button id="btn-left" class="btn" data-dir="left" aria-label="Move left" type="button">←</button>
<button id="btn-up" class="btn" data-dir="up" aria-label="Move up" type="button">↑</button>
<button id="btn-down" class="btn" data-dir="down" aria-label="Move down" type="button">↓</button>
<button id="btn-right" class="btn" data-dir="right" aria-label="Move right" type="button">→</button>
</div>
<div id="scoreboard" role="status" aria-live="polite" aria-atomic="true" aria-label="Scoreboard">
Score: <span class="score-current" id="currentScore">0</span> | High: <span class="score-high" id="highScore">0</span>
</div>
<button id="restartBtn" type="button" aria-label="Restart game" tabindex="0">Restart Game</button>
</div>
<!-- Sound effect file -->
<audio id="eatSfx" src="eat.mp3" preload="auto" aria-hidden="true"></audio>
<script>
(() => {
const game = document.getElementById('game');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const trailCanvas = document.getElementById('trailCanvas');
const trailCtx = trailCanvas.getContext('2d');
const particlesCanvas = document.getElementById('particles');
const pctx = particlesCanvas.getContext('2d');
const scoreEl = document.getElementById('currentScore');
const highEl = document.getElementById('highScore');
const sb = document.getElementById('scoreboard');
const eatSfx = document.getElementById('eatSfx');
const btns = document.querySelectorAll('.btn');
const restartBtn = document.getElementById('restartBtn');
// Config & state
const tileCount = 24;
let gridSize;
const baseFPS = 15;
let fps = baseFPS;
const maxApples = 4;
let snake, velocity, nextVel, apples, score, gameOver;
let comboCounter, lastAppleTime, hue;
let effects;
let highScore = parseInt(localStorage.getItem('snakeHighScore'), 10) || 0;
highEl.textContent = highScore;
// Timing for fixed FPS using delta accumulator
let lastTime = 0;
let delta = 0;
const interval = 1000 / fps;
// Particles and trails data
let particles = [];
let trailPoints = [];
// Resize canvas & related
function resizeCanvas() {
const size = game.clientWidth;
canvas.width = size;
canvas.height = size;
trailCanvas.width = size;
trailCanvas.height = size;
particlesCanvas.width = size;
particlesCanvas.height = size;
gridSize = size / tileCount;
}
resizeCanvas();
window.addEventListener('resize', () => {
resizeCanvas();
});
// Color gradient helpers
function colorGradient(isSnake) {
hue = (hue + 1.3) % 360;
if (isSnake) {
const c1 = `hsl(${hue}, 100%, 62%)`;
const c2 = `hsl(${(hue + 60) % 360}, 85%, 55%)`;
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
gradient.addColorStop(0, c1);
gradient.addColorStop(1, c2);
return gradient;
} else {
const gradient = ctx.createRadialGradient(0, 0, 6, 0, 0, gridSize * 0.7);
gradient.addColorStop(0, `hsl(${hue}, 100%, 75%)`);
gradient.addColorStop(1, `hsl(${(hue + 45) % 360}, 90%, 45%)`);
return gradient;
}
}
// Rounded rect for snake and apple
function roundedRect(x,y,w,h,r, ctxOverride = ctx) {
const ctxToUse = ctxOverride;
ctxToUse.beginPath();
ctxToUse.moveTo(x + r, y);
ctxToUse.lineTo(x + w - r, y);
ctxToUse.quadraticCurveTo(x + w, y, x + w, y + r);
ctxToUse.lineTo(x + w, y + h - r);
ctxToUse.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctxToUse.lineTo(x + r, y + h);
ctxToUse.quadraticCurveTo(x, y + h, x, y + h - r);
ctxToUse.lineTo(x, y + r);
ctxToUse.quadraticCurveTo(x, y, x + r, y);
ctxToUse.closePath();
ctxToUse.fill();
}
function isCellEmpty(x, y) {
return !snake.some(s => s.x === x && s.y === y)
&& !apples.some(a => a.x === x && a.y === y);
}
// Apple spawning with random positions
function spawnApples() {
while(apples.length < maxApples){
const p = {
x: Math.floor(Math.random() * tileCount),
y: Math.floor(Math.random() * tileCount)
};
if (isCellEmpty(p.x, p.y)) {
apples.push(p);
}
}
}
// Particle System
class Particle {
constructor(x, y, dx, dy, size, color, life) {
this.x = x;
this.y = y;
this.dx = dx;
this.dy = dy;
this.size = size;
this.color = color;
this.life = life;
this.alpha = 1;
}
update() {
this.x += this.dx;
this.y += this.dy;
this.life -= 1;
this.alpha = Math.max(0, this.life / 30);
this.size *= 0.92;
}
draw(ctx) {
ctx.save();
ctx.globalAlpha = this.alpha;
ctx.fillStyle = this.color;
ctx.shadowColor = this.color;
ctx.shadowBlur = 14;
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, 2 * Math.PI);
ctx.fill();
ctx.restore();
}
}
function addParticles(x, y, count=12) {
for(let i=0; i<count; i++){
const angle = Math.random()*2*Math.PI;
const speed = Math.random()*3 + 2;
const dx = Math.cos(angle)*speed;
const dy = Math.sin(angle)*speed;
const size = Math.random()*3 + 2;
const color = `hsl(${(hue + Math.random()*60) % 360}, 100%, 70%)`;
particles.push(new Particle(x, y, dx, dy, size, color, 30));
}
}
// Score pop-up text effect
function addScoreEffect(x,y, amt) {
effects.score.push({
x: x*gridSize + gridSize/2,
y: y*gridSize + gridSize/2,
alpha: 1,
text: '+' + amt,
size: 26 + Math.random() * 10,
riseSpeed: 1 + Math.random()*1.2
});
}
// Effects
effects = { score: [], particles: [] };
// Draw glow trail behind snake by fading previous frames & drawing blurred snake positions
function drawTrail() {
trailCtx.fillStyle = 'rgba(0, 255, 187, 0.042)';
trailCtx.fillRect(0, 0, trailCanvas.width, trailCanvas.height);
trailCtx.shadowColor = `hsl(${hue}, 100%, 70%)`;
trailCtx.shadowBlur = 14;
trailCtx.fillStyle = `hsl(${hue}, 100%, 50%)`;
trailPoints.forEach(({x,y,alpha}, i) => {
trailCtx.globalAlpha = alpha * (0.25 + (i / trailPoints.length) * 0.75);
roundedRect(x, y, gridSize, gridSize, gridSize*0.3, trailCtx);
});
trailCtx.globalAlpha = 1;
}
// Draw particles on particles canvas
function drawParticles() {
pctx.clearRect(0, 0, particlesCanvas.width, particlesCanvas.height);
particles.forEach(p => p.draw(pctx));
}
// Draw main game canvas: grid, apples, snake, effects
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw grid softly
ctx.strokeStyle = '#00222244';
ctx.lineWidth = 1;
for(let i=0; i <= tileCount; i++) {
const pos = i * gridSize;
ctx.beginPath();
ctx.moveTo(pos, 0);
ctx.lineTo(pos, canvas.height);
ctx.moveTo(0, pos);
ctx.lineTo(canvas.width, pos);
ctx.stroke();
}
// Draw apples
apples.forEach(a => {
const cx = a.x * gridSize + gridSize/2;
const cy = a.y * gridSize + gridSize/2;
ctx.save();
ctx.translate(cx, cy);
ctx.shadowColor = '#ff0044';
ctx.shadowBlur = 25;
ctx.fillStyle = colorGradient(false);
ctx.beginPath();
ctx.ellipse(0, 0, gridSize*0.45, gridSize*0.7, Math.PI/7, 0, 2*Math.PI);
ctx.fill();
// leaf highlight
ctx.fillStyle = '#330022cc';
ctx.beginPath();
ctx.ellipse(0, -gridSize*0.35, gridSize*0.18, gridSize*0.42, Math.PI/4, 0, 2*Math.PI);
ctx.fill();
ctx.restore();
});
// Draw snake - glowing main body with gradient
snake.forEach(({x,y}, i) => {
const px = x * gridSize;
const py = y * gridSize;
ctx.save();
ctx.shadowColor = '#00ffbbcc';
ctx.shadowBlur = (i === 0) ? 28 : 18;
ctx.fillStyle = colorGradient(true);
roundedRect(px+2, py+2, gridSize-4, gridSize-4, gridSize*0.25);
ctx.restore();
});
// Draw effects: score popup texts
effects.score.forEach((e, idx) => {
ctx.fillStyle = `rgba(0,255,187,${e.alpha})`;
ctx.font = `bold ${e.size}px 'Share Tech Mono', monospace`;
ctx.textAlign = 'center';
ctx.shadowColor = '#0ff';
ctx.shadowBlur = 14;
ctx.fillText(e.text, e.x, e.y);
// Update effect
e.y -= e.riseSpeed;
e.alpha -= 0.025;
e.size += 0.3;
if(e.alpha <= 0) effects.score.splice(idx, 1);
});
}
// Add haptic feedback vibration if supported
function vibrate(length=10) {
if('vibrate' in navigator) {
navigator.vibrate(length);
}
}
// Game initialization or reset
function initGame() {
snake = [{x:12,y:12}, {x:11,y:12}, {x:10,y:12}];
velocity = {x:1, y:0};
nextVel = {x:1, y:0};
apples = [];
score = 0;
comboCounter = 0;
lastAppleTime = 0;
hue = 0;
effects = {score: [], particles: []};
particles = [];
trailPoints = [];
fps = baseFPS;
scoreEl.textContent = score;
restartBtn.style.display = 'none';
spawnApples();
}
// Game logic update
function update() {
if(gameOver) return;
// Prevent reversing direction abruptly
if((nextVel.x !== -velocity.x || nextVel.y !== -velocity.y)
&& (nextVel.x !== velocity.x || nextVel.y !== velocity.y)) {
velocity = nextVel;
}
const head = {
x: (snake[0].x + velocity.x + tileCount) % tileCount,
y: (snake[0].y + velocity.y + tileCount) % tileCount
};
// Check collision with self - game over condition
if(snake.some(p => p.x === head.x && p.y === head.y)) {
gameOver = true;
playGameOverEffect();
showGameOver();
return;
}
snake.unshift(head);
// Add to trail points, fading old ones gradually
let newTrailX = head.x * gridSize + 2;
let newTrailY = head.y * gridSize + 2;
trailPoints.unshift({x: newTrailX, y: newTrailY, alpha: 1});
if(trailPoints.length > 40) {
trailPoints.pop();
}
trailPoints.forEach(tp => tp.alpha *= 0.92);
let ate = false;
for(let i=0; i<apples.length; i++){
if(apples[i].x === head.x && apples[i].y === head.y){
const now = Date.now();
const timeBonus = (now - lastAppleTime < 3000) ? 5 : 0;
const comboBonus = comboCounter * 2;
const gain = 10 + timeBonus + comboBonus;
score += gain;
comboCounter++;
lastAppleTime = now;
scoreEl.textContent = score;
if(score > highScore){
highScore = score;
localStorage.setItem('snakeHighScore', highScore);
highEl.textContent = highScore;
}
addScoreEffect(head.x, head.y, gain);
addParticles(head.x * gridSize + gridSize/2, head.y * gridSize + gridSize/2);
flashScore();
vibrate(40);
try {
eatSfx.currentTime = 0;
eatSfx.play();
} catch(e){}
apples.splice(i,1);
spawnApples();
ate = true;
fps = Math.min(30, baseFPS + Math.floor(score / 25)); // speed up with score
break;
}
}
if(!ate){
comboCounter = 0;
snake.pop();
}
// Update particles
for(let i=particles.length-1; i>=0; i--) {
const p = particles[i];
p.update();
if(p.life <= 0 || p.size <= 0.2) particles.splice(i, 1);
}
}
// Flash effect on scoreboard when score updates
function flashScore() {
sb.classList.add('flash');
setTimeout(() => sb.classList.remove('flash'), 200);
}
// Game Over effects
function playGameOverEffect() {
for(let i=0; i<60; i++){
addParticles(
(snake[0].x + (Math.random()*2-1)) * gridSize + gridSize/2,
(snake[0].y + (Math.random()*2-1)) * gridSize + gridSize/2,
Math.floor(Math.random()*20));
}
vibrate([100,50,100]);
}
// Show Game Over alert & reveal restart
function showGameOver() {
setTimeout(() => {
alert(`Game Over!\nYour score: ${score}`);
restartBtn.style.display = 'block';
restartBtn.focus();
}, 150);
}
// Input handling
let touchStart = null;
const minSwipe = 30;
// Keyboard support: arrows + WASD
window.addEventListener('keydown', e => {
if(gameOver) return; // ignore input if game over
const keyMap = {
ArrowUp: 'up', w: 'up', W: 'up',
ArrowDown: 'down', s: 'down', S: 'down',
ArrowLeft: 'left', a: 'left', A: 'left',
ArrowRight: 'right', d: 'right', D: 'right'
};
const dir = keyMap[e.key];
if(dir) {
e.preventDefault();
changeDir(dir);
}
});
// Direction change helper
function changeDir(dir) {
const map = { up:{x:0,y:-1}, down:{x:0,y:1}, left:{x:-1,y:0}, right:{x:1,y:0} };
const nv = map[dir];
if(nv && (nv.x !== -velocity.x || nv.y !== -velocity.y)) nextVel = nv;
}
// Buttons click handlers
btns.forEach(b => b.addEventListener('click', () => changeDir(b.dataset.dir)));
// Touch support - swipe detection
canvas.addEventListener('touchstart', e => {
if(e.touches.length === 1) {
touchStart = { x: e.touches[0].clientX, y: e.touches[0].clientY };
}
}, { passive: true });
canvas.addEventListener('touchmove', e => {
if(!touchStart) return;
const dx = e.touches[0].clientX - touchStart.x;
const dy = e.touches[0].clientY - touchStart.y;
if(Math.abs(dx) > minSwipe || Math.abs(dy) > minSwipe){
const dir = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 'right' : 'left') : (dy > 0 ? 'down' : 'up');
changeDir(dir);
touchStart = null;
}
}, { passive: true });
canvas.addEventListener('touchend', () => { touchStart = null; });
// Restart button click handler
restartBtn.addEventListener('click', () => {
gameOver = false;
initGame();
});
// Main loop with fixed FPS using delta accumulator
function loop(ts=0) {
if(!lastTime) lastTime = ts;
delta += ts - lastTime;
lastTime = ts;
while(delta >= 1000 / fps) {
update();
delta -= 1000 / fps;
}
draw();
drawTrail();
drawParticles();
requestAnimationFrame(loop);
}
// Initialization
initGame();
requestAnimationFrame(loop);
})();
</script>
</body>
</html>