All game parameters are defined as named constants at the very top of theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ac-unefm/snake-game/llms.txt
Use this file to discover all available pages before exploring further.
<script> block in index.html, and all visual design tokens are CSS custom properties declared in the :root block inside the <style> tag. Customizing the game means editing these values directly in index.html — open the file in any text editor, make your change, save, and refresh the browser. No build step, no package manager, and no toolchain is required.
Speed & difficulty constants
The four speed constants control how fast the game starts, how fast it can get, and how quickly difficulty ramps up as the player scores.index.html — speed constants
getTick(score):
BASE_TICK — starting game speed
BASE_TICK — starting game speed
The interval in milliseconds between each snake movement at the beginning of a game (score = 0, level = 1).
- Default:
130ms ≈ ~7.7 moves per second. - Slower / beginner-friendly: increase to
200— the snake starts noticeably slower, giving new players more reaction time. - Faster start: decrease to
80— the game opens at a challenging pace right from the first move.
MIN_TICK — maximum speed cap
MIN_TICK — maximum speed cap
The shortest interval (in ms) the game loop will ever use, no matter how high the score climbs. This prevents the game from becoming physically unplayable at very high levels.
- Default:
45ms ≈ ~22 moves per second. - More extreme cap: decrease to
30— experienced players will face a genuinely demanding speed ceiling. - Gentler cap: increase to
60— limits how fast the game can get, keeping it accessible at high scores.
STEP_SCORE — points needed to level up
STEP_SCORE — points needed to level up
How many points the player must score before the snake speeds up by one level.
- Default:
5— the game speeds up every 5 food items eaten. - Slower progression: increase to
10— the game stays at each speed longer before levelling up. - Faster progression: decrease to
3— the difficulty ramps up very aggressively from the start.
STEP_MS — speed increase per level
STEP_MS — speed increase per level
How many milliseconds are shaved off the tick interval each time the player levels up.
- Default:
12ms per level. - More dramatic speed increase: raise to
20— each level-up is a noticeably bigger jump in pace. - Smoother progression: lower to
6— levels feel more gradual; the game eases into higher speeds.
Grid size
GRID_SIZE controls the pixel size of each cell on the 400×400 canvas. The number of columns and rows is derived at runtime by dividing the canvas dimensions by GRID_SIZE.
index.html — grid constants
GRID_SIZE.
GRID_SIZE value | Grid layout | Character |
|---|---|---|
10 | 40 × 40 cells | Dense, harder — more room to navigate |
20 | 20 × 20 cells | Default balance |
40 | 10 × 10 cells | Large cells, simple — good for beginners |
width and height HTML attributes on the <canvas> element and, if desired, adjust the max-width CSS property on #game-region:
Session length
SESSION_ATTEMPTS controls how many consecutive attempts make up one session. After all attempts are exhausted, the session results panel is displayed with per-attempt statistics and aggregated session metrics.
index.html — session constant
3— a quick session; useful for short play breaks.5— the default; balanced pacing with a meaningful stats summary.10— a marathon format; session stats become more statistically meaningful with larger samples.
session-dot elements in the HTML to match — there is one <span class="session-dot"> per attempt in the #session-bar div:
dots array initializer in JS (currently Array.from({ length: 5 }, ...)) to use the new count.
Color palette
Colors are defined in two places: the CSS:root block (used by all HTML/CSS UI elements — HUD, buttons, overlays, session dots) and the JS COLORS object (used by the canvas 2D renderer for grid lines, food, and snake segments). To change the look of the game completely, update both.
index.html — CSS custom properties
index.html — canvas palette
Swipe sensitivity
SWIPE_MIN_PX sets the minimum finger travel distance in pixels before a touch gesture is classified as a directional swipe. If the finger moves less than this threshold in both axes, the touch is treated as a tap (which starts or continues the game) rather than a movement command.
index.html — swipe threshold
- More sensitive (
10): very short swipes register as directional input — useful for players with precise control, but may cause accidental direction changes. - Default (
20): a comfortable middle ground that filters out minor finger tremor. - Less sensitive (
40): requires a more deliberate swipe — reduces accidental moves, but can feel sluggish on very small screens.
Example: making a lighter theme
The default palette uses a near-black background designed for dark environments. Here is a concrete example of switching to a light theme by overriding the CSS custom properties:draw() function:
draw() function and change the fill color to match your new --color-surface, for example:
COLORS.grid to a color that is visible against the new canvas background: