Neon Snake Game Documentation

Comprehensive documentation covering decoupled fixed timestep game loop, Web Audio API procedural sound synthesizer, and particle physics.

Neon Snake Engine Architecture

Neon Snake Game is built strictly with Vanilla JavaScript and HTML5 Canvas API. It does not load external sprite sheets or sound audio files—all visual bloom, particle effects, and sound synthesizer waveforms are computed procedurally on-the-fly.

Graphics EngineHTML5 2D Canvas Context (60 FPS)
Audio SystemWeb Audio API AudioContext Synthesizer
ParticlesRadial dispersion physics with alpha decay
Zero Dependencies100% self-contained Vanilla JS
# Clone the repository
git clone https://github.com/dev-hints/Snake-Game.git
cd Snake-Game

# Launch game locally in any web browser
open index.html

Fixed Timestep Game Loop

Rendering is decoupled from game state physics using an accumulator loop:

// Decoupled tick update
function gameLoop(timestamp) {
  let delta = timestamp - lastTime;
  lastTime = timestamp;
  accumulator += delta;

  while (accumulator >= TICK_RATE) {
    updateSnakePhysics();
    accumulator -= TICK_RATE;
  }

  renderCanvas(accumulator / TICK_RATE);
  requestAnimationFrame(gameLoop);
}

Procedural Web Audio Synthesizer

Audio feedback utilizes AudioContext oscillators with custom attack-decay-sustain-release (ADSR) gain curves:

Sound Event Oscillator Waveform Base Frequency Envelope Duration
Food PickupSine Wave587 Hz (D5) ➔ 880 Hz (A5)80 ms
Power-Up ActiveTriangle Wave440 Hz (A4) Arpeggio220 ms
Wall CollisionSquare Wave + Noise110 Hz (A2) ➔ 55 Hz (A1)350 ms
Combo StreakSine Harmonizer880 Hz + (Streak * 100 Hz)120 ms

Input & Gesture Mapping

Supports full directional prevention against 180-degree self-collisions:

Input Method Trigger Binding
Arrow Keys / W A S DCardinal direction steering
Touch Swipe Up/Down/Left/RightMobile gesture direction tracking
SpacebarPause / Resume game session
RInstant restart run