COLS
number
The fixed width of the level grid in tiles (20 columns)
const COLS = 20;
ROWS
number
The fixed height of the level grid in tiles (14 rows)
const ROWS = 14;
TILE_EMPTY / TILE_BLOCK / TILE_LADDER / TILE_GOLD / TILE_HOLE
string
Single-character constants representing each possible tile type stored in the level grid, used everywhere instead of hardcoded string literals
const TILE_BLOCK = '#';
MOVE_SPEED
number
How much progress the player's slide animation advances per frame, controlling player speed
const MOVE_SPEED = 0.15;
ENEMY_SPEED
number
How much progress an enemy's slide animation advances per frame, controlling enemy speed
const ENEMY_SPEED = 0.08;
ENEMY_PAUSE
number
Number of frames an enemy waits between movement decisions
const ENEMY_PAUSE = 8;
HOLE_DURATION
number
Number of frames a dug hole stays open before resealing into brick
const HOLE_DURATION = 240;
START_LIVES
number
How many lives a new game begins with
const START_LIVES = 3;
SCORE_PER_GOLD
number
Points awarded for each gold coin collected
const SCORE_PER_GOLD = 100;
LEVEL_CLEAR_BONUS
number
Flat bonus points awarded for finishing a level
const LEVEL_CLEAR_BONUS = 500;
TIME_BONUS_PER_SECOND
number
Multiplier used to convert unused time into bonus score on level completion
const TIME_BONUS_PER_SECOND = 5;
levelTemplate
array
The human-readable ASCII strings describing the level layout; mutated in place when the level editor applies a new design
const levelTemplate = ["####...#", ...];
level
array
The live 2D array of tile characters built from levelTemplate, actually used by all game logic and rendering
let level = [];
player
object
The single player entity object holding position, animation, and movement state
let player = null;
enemies
array
Array of enemy entity objects, each with its own position and AI state
let enemies = [];
holes
array
Tracks currently-dug holes with their countdown timers so they can reseal automatically
let holes = [];
goldTotal / goldCollected
number
Track how much gold exists in the level versus how much has been picked up, used for the HUD and win condition
let goldTotal = 0;
tileSize
number
The pixel size of one grid tile, recalculated whenever the screen resizes
let tileSize;
offsetX / offsetY
number
The pixel offset used to center the grid within the canvas
let offsetX;
gameState
string
The current phase of the game: 'playing', 'won', or 'gameover', used to gate logic and control HUD messages
let gameState = 'playing';
lives
number
How many lives the player currently has left
let lives = START_LIVES;
score
number
The player's running score across the current run
let score = 0;
levelStartFrame
number
The frameCount value recorded when the current level began, used to calculate elapsed time
let levelStartFrame = 0;
lastLevelTimeSec
number
The frozen elapsed time (in seconds) recorded when a level ends, shown on the HUD after winning or losing
let lastLevelTimeSec = 0;
controls
object
Unified boolean state for left/right/up/down movement, combined from keyboard and touch/mouse input each frame
let controls = { left: false, right: false, up: false, down: false };
buttons
array
Holds all six UIButton instances so input and drawing code can loop over them generically
let buttons = [];
btnLeft, btnRight, btnUp, btnDown, btnDigLeft, btnDigRight
object
Individual named references to each on-screen touch button, created in setupControls()
let btnLeft, btnRight, btnUp, btnDown, btnDigLeft, btnDigRight;
audioCtx
object
The single Web Audio API AudioContext used to generate all sound effects
let audioCtx = null;
masterGain
object
A shared gain (volume) node all sounds are routed through, controlling overall game volume
let masterGain = null;
editorVisible
boolean
Whether the DOM level editor overlay is currently open, used to pause the game and gameplay input
let editorVisible = false;
editorOverlay, editorTextarea, editorError
object
References to the DOM elements making up the level editor UI (the fullscreen overlay, the text input, and the error message div)
let editorOverlay = null;